Reputation: 9722
The JSON:
{
"count": 1,
"rows": [
{
"user_id": "7",
"lat": "48.452583",
"lng": "-123.545052",
"distance": "0.4852177729308128"
}
]
}
This comes into my function(data)
and I'm trying to access count
and then the user_id
..
downloadUrl(searchUrl, function(data) {
alert( "Locations Found: " + data[0].count );
});
data.count
, data[0].count
... don't work. And I'm drawing a blank as to how to access them.
Upvotes: 0
Views: 113
Reputation: 146219
If your data
is string (not data-type:json) then you need to parse it as follows
var obj=$.parseJSON(data);
Then use
obj.count;
obj.rows[0].user_id;
Upvotes: 3
Reputation: 478
Is data really an Object or just a string. You can debug type with most browser's console by doing console.log(typeof data) or alternatively alert(typeof data).
Upvotes: 0
Reputation: 5640
try this
data = {"count":1,"rows":[{"user_id":"7","lat":"48.452583","lng":"-123.545052","distance":"0.4852177729308128"}]}
data.count
data.rows[0].user_id
Upvotes: 0