0

I am trying to read a json string which looks like this.

"student":{
    "0":[{
        "name":"manet",
        "marks":114
    }],
    "1":null,
    "2":null,
    "3":null,
    "4":null,
    "5":null,
    "6":null,
    "7":null,
    "8":null,
    "9":null,
    "10":null,
    "18":[{
        "name":"Om",
        "marks":75
    }]
}

I am trying to read something like this

console.log("JSON Marks ", json[0].marks) or
console.log("JSON Marks #1", json[0][0].marks)

I just put jso[0] "0" is index i just put hardcoded to test

but none of the above is working

Cerbrus
  • 70,800
  • 18
  • 132
  • 147
user3290805
  • 445
  • 2
  • 10
  • 28

3 Answers3

1

assuming that your code is saved in a variable called json then json.student[0][0].marks

AhmadAssaf
  • 3,556
  • 5
  • 31
  • 42
0

You need this : http://jsbin.com/qazex/2/edit

console.log("JSON Marks ", json["student"][0][0].marks)

var json={"student":{
    "0":[{
        "name":"manet",
        "marks":114
    }],
    "1":null,
    "2":null,
    "3":null,
    "4":null,
    "5":null,
    "6":null,
    "7":null,
    "8":null,
    "9":null,
    "10":null,
    "18":[{
        "name":"Om",
        "marks":75
    }]
}};
console.log("JSON Marks ", json["student"][0][0].marks)
Royi Namir
  • 144,742
  • 138
  • 468
  • 792
0

Try this way to access to object

var json = {"student":{
    "0":[{
        "name":"manet",
        "marks":114
    }],
    "1":null,
    "2":null,
    "3":null,
    "4":null,
    "5":null,
    "6":null,
    "7":null,
    "8":null,
    "9":null,
    "10":null,
    "18":[{
        "name":"Om",
        "marks":75
    }]
}
}
alert("JSON Marks "+ json["student"]["0"]["0"]["marks"]) ;

JSFIDDLE

Suresh Mahawar
  • 1,458
  • 15
  • 34