javascript - How to traverse each property of JSON string -


i have json coming database

[   {     "id": "0001",     "type": "donut",     "name": "cake",     "ppu": 0.55,     "batters": {       "batter": [         { "id": "1001", "type": "regular" },         { "id": "1002", "type": "chocolate" },         { "id": "1003", "type": "blueberry" },         { "id": "1004", "type": "devil's food" }       ]     },     "topping": [       { "id": "5001", "type": "none" },       { "id": "5002", "type": "glazed" },       { "id": "5005", "type": "sugar" },       { "id": "5007", "type": "powdered sugar" },       { "id": "5006", "type": "chocolate sprinkles" },       { "id": "5003", "type": "chocolate" },       { "id": "5004", "type": "maple" }     ]   },   {     "id": "0002",     "type": "donut",     "name": "raised",     "ppu": 0.55,     "batters": {       "batter": [         { "id": "1001", "type": "regular" }       ]     },     "topping": [       { "id": "5001", "type": "none" },       { "id": "5002", "type": "glazed" },       { "id": "5005", "type": "sugar" },       { "id": "5003", "type": "chocolate" },       { "id": "5004", "type": "maple" }     ]   } ] 

i trying traverse properties of above json below jquery ajax call method

$.ajax({   url: 'mypage.aspx/callingfunction',   type: 'post',   data: '{}',   contenttype: 'application/json; charset=utf-8',   datatype: 'json',   success: function(data) {     alert(data.d) // showing json fine     var mydata = $.parsejson(data.d);     (i = 0; < mydata.length; i++) {       //how travers properties defined in json     }   } }); 

object.keys() give want:

var i, key, value; var keys = object.keys(mydata); (i = 0; < keys.length; i++) {   key = keys[i];   value = mydata[key];   // ... } 

Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -