Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to parse multi dimensional JSON data through Javascript

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": "[email protected]",
        "street": "mystreet",
        "city": "mycity",
        "state": "mystate",
        "zipcode": "123456",
        "myimage": "image.gif"}
    ]
}​
like image 885
swapnesh Avatar asked Apr 10 '12 06:04

swapnesh


1 Answers

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": "[email protected]",
        "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...
like image 85
Joseph Avatar answered Oct 28 '22 23:10

Joseph