Home > DeveloperSection > Forums > how to iterating over json data
C G E Mannerheim
C G E Mannerheim

Total Post:29

Points:203
Posted on    June-20-2013 3:15 AM

 JSON JSON 
Ratings:


 1 Reply(s)
 946  View(s)
Rate this:
Hi All,

following is my json data in a div,

[{"Identifier":"1","Label":"10 Day","Categories":"Standard","UpdatedBy":"Lno","UpdatedAt":"01-02-2013","RefId":"0","ComType":"1","Cs":["944"],"AM":"Error 

Message","Message":"asdfasdf","Combiner":[{"uniqueID":"1","type":"7","rule":""}]}]
I am accessing it thorugh a js object var myArrayVar=JSON.parse(document.getElementById("populateDT").innerHTML);

I want to iterate over this js object following is the code i am trying but it doesnot access my key, value fields

for( var  i=0; i<=myArrayVar.length;i++){
            for(var j=0; j<=myArrayVar.Combiner.length; j++){
                var sessionUniqueId= myArrayVar.Combiner[j].uniqueID;
                alert(sessionUniqueId);
                var sessionType=myArrayVar.Combiner[j].type;
                alert(sessionType);
                var sessionRule=myArrayVar.Combiner[j].rule;
                alert(sessionRule);
            }
        }
can anyone suggests whats going wrong



AVADHESH PATEL

Total Post:604

Points:4228
Posted on    June-20-2013 7:37 AM

Hi,

Try using "<" instead of "<=" in the for loops, and "myArrayVar[i].Combiner" instead of "myArrayVar.Combiner".

Don't want to miss updates? Please click the below button!

Follow MindStick