I got this JSON. I want to get the value of "resource_uri" that is "/api/v1/client/2/".
I'm using Backbone/javascript.
json['resource_uri'] does not work.
The JSON is:
{
"meta": {
"limit": 20,
"next": null,
"offset": 0,
"previous": null,
"total_count": 1
},
"objects": [
{
"id": 2,
"nom": "",
"resource_uri": "/api/v1/client/2/",
"telefon": "",
"user": {
"date_joined": "2013-05-15T12:28:40",
"first_name": "",
"id": 51,
"is_active": true,
"is_staff": false,
"last_login": "2013-05-16T06:20:43",
"last_name": "",
"resource_uri": "/api/v1/user/51/",
"username": "gli"
}
}
]
}
Thanks in advance.
The value you're looking for, is in the objects array in the JSON, but it's in an object which is the first in an array:
var jsonVar = {"meta": {"limit": 20, "next": null, "offset": 0, "previous": null, "total_count": 1}, "objects": [{"id": 2, "nom": "", "resource_uri": "/api/v1/client/2/", "telefon": "", "user": {"date_joined": "2013-05-15T12:28:40", "first_name": "", "id": 51, "is_active": true, "is_staff": false, "last_login": "2013-05-16T06:20:43", "last_name": "", "resource_uri": "/api/v1/user/51/", "username": "gli"}}]}
alert(jsonVar.objects[0].resource_uri);
See here:
http://jsfiddle.net/SpAm/tnWmL/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With