javascript - How to read array inside JSON Object this is inside another array -
i newbie json, parsing json object , struck @ point have read array elements inside object, again in array.. here json
{ "definitionsource": "test", "relatedtopics": [ { "result": "", "icon": { "url": "https://duckduckgo.com/i/a5e4a93a.jpg" }, "firsturl": "xyz", "text": "sample." }, { "result": "", "icon": { "url": "xyz" }, "firsturl": "xyz", "text": "sample." }, { "topics": [ { "result": "", "icon": { "url": "https://duckduckgo.com/i/10d02dbf.jpg" }, "firsturl": "https://duckduckgo.com/snake_indians", "text": "sample" }, { "result": "sample", "icon": { "url": "https://duckduckgo.com/i/1b0e4eb5.jpg" }, "firsturl": "www.google.com", "text": "xyz." } ] } ] }
here need read url ,firsturl , text relatedtopics array , topics array.. can me. in advance.
something this
function (json) { json.relatedtopics.foreach(function (element) { var url = element.icon ? element.icon.url : 'no defined'; var firsturl = element.firsturl ? element.firsturl : 'no defined'; var text = element.text ? element.text : 'no defined'; alert("url: " + url + "\nfirsturl: " + firsturl + "\ntext: " + text); if (element.topics) { element.topics.foreach(function (topicelement) { alert("topics - \n" + "url: " + topicelement.icon.url + "\nfirsturl: " + topicelement.firsturl + "\ntext: " + topicelement.text); }); } }); };
Comments
Post a Comment