javascript - Object retrieval from JSON using Jquery / JS -
i have json file @ /path/to/json containing:
{"a": {"s": [{"l": "ppp"}]}}
i'm using jquery expression:
$.ajax({ url: '/path/to/json', datatype: 'json', async: false, success: function(data) { $.each(data.a.s, function(index,element) { lines=element.l; }) } });
how return value @ a.s.l without using $.each()?
i have json file containing:
{"a": {"s": [ { "l": "ppp", "qqq": "aaa" }, { "l": "fff", "qqq": "bbb" } ]}}
this file. how assign contents of file variable search within json object who's 'l' attribute 'ppp' retrieve object's 'qqq' value?
you can use array index, if know index of item fetched
to first item in s
array
data.a.s[0].l
to second item in s
array
data.a.s[1].l
or use loop
for(var i= 0; i<data.a.s.length; i++){ lines = data.a.s[i].l }
Comments
Post a Comment