javascript - Object retrieval from JSON using Jquery / JS -


  1. 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()?

  2. 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

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -