Somsekhar Dash
Somsekhar Dash

Reputation: 35

parse nested JSON using JQuery

i want to get the "Name" value (i.e xyz,abc,mno,mxc) from the json data, but as the parent node ids are different i am not able to parse it ..??

"all": {
    "id55": {
        "Tid": "1",
        "Name": "xyz",
        "TypeName": "author"
    },
    "id56": {
        "Tid": "2",
        "Name": "abc",
        "TypeName": "author"
    },
    "id57": {
        "Tid": "3",
        "Name": "mno",
        "TypeName": "author"
    },
    "id58": {
        "Tid": "4",
        "Name": "mzc",
        "TypeName": "author"
    },
}

Upvotes: 1

Views: 440

Answers (2)

Felix
Felix

Reputation: 38102

You can use $.each() to iterate over your object and get Name value:

$.each(all, function(i,val) {
   console.log(all[i].Name);
});

Fiddle Demo

Upvotes: 2

CrayonViolent
CrayonViolent

Reputation: 32532

var all = {
            "id55": {
                "Tid": "1",
                "Name": "xyz",
                "TypeName": "author"
            },
            "id56": {
                "Tid": "2",
                "Name": "abc",
                "TypeName": "author"
            },
            "id57": {
                "Tid": "3",
                "Name": "mno",
                "TypeName": "author"
            },
            "id58": {
                "Tid": "4",
                "Name": "mzc",
                "TypeName": "author"
            }
        }
for (var a in all) {
  console.log(all[a].Name);
}

output

xyz
abc
mno
mzc

Upvotes: 3

Related Questions