Javascript – How to parse multi dimensional JSON data through Javascript

javascriptjson

How could i parse this type of json data, getting in "results" to fetch single values like zipcode, state etc

{
    "row": [
        {
        "id": "5",
        "name": "test",
        "email": "test@test.com",
        "street": "mystreet",
        "city": "mycity",
        "state": "mystate",
        "zipcode": "123456",
        "myimage": "image.gif"}
    ]
}​

Best Solution

first, you need to parse that string with JSON.parse

var myJson = JSON.parse(the_raw_data_string);

it ends up into an object like this:

var myJson = {
    "row": [
        {
        "id": "5",
        "name": "test",
        "email": "test@test.com",
        "street": "mystreet",
        "city": "mycity",
        "state": "mystate",
        "zipcode": "123456",
        "myimage": "image.gif"}
    ]
}​

accessing the items:

myJson.row[0].id
myJson.row[0].name
myJson.row[0].street
//and so on...