[jQuery] json parser doesn't output

[jQuery] json parser doesn't output


I've been trying to get this to work following these instructions
http://blog.reindel.com/2007/10/02/parse-json-with-jquery-and-javascript/
, but i can't seem to get any output.
I am getting json data from google maps getLocations(), so the way I
grab the json is a bit different.
according to google, the json looks like this
[code]
{
"name": "1600 Amphitheatre Parkway, Mountain View, CA, USA",
"Status": {
"code": 200,
"request": "geocode"
},
"Placemark": [
{
"address": "1600 Amphitheatre Pkwy, Mountain View, CA 94043,
USA",
"AddressDetails": {
"Country": {
"CountryNameCode": "US",
"AdministrativeArea": {
"AdministrativeAreaName": "CA",
"SubAdministrativeArea": {
"SubAdministrativeAreaName": "Santa Clara",
"Locality": {
"LocalityName": "Mountain View",
"Thoroughfare": {
"ThoroughfareName": "1600 Amphitheatre Pkwy"
},
"PostalCode": {
"PostalCodeNumber": "94043"
}
}
}
}
},
"Accuracy": 8
},
"Point": {
"coordinates": [-122.083739, 37.423021, 0]
}
}
]
}
[/code]
I don't get any errors, but firefox shows the script stopping on line
745 which is something about object length== undefined.
I assume that because I can alert
the code i am using to try to parse the json is and get the accuracy
is
[code]
var jJSON = {
getValues: function(obj,num) {
return jJSON[obj]["values"].slice(0,((num == null) ? jJSON[obj]
["values"].length : num));
},
getCount: function(obj) {
return jJSON[obj]["count"];
},
getRandomValues: function(obj,num) {
var a = [];
var b = jJSON[obj]["values"];
var c = b.length;
if (num != null && num < c) {
c = num;
}
for (i = 0; i < c; i++) {
var e = Math.floor(Math.random() * b.length);
a[i] = b[e];
b.splice(e,1);
}
return a;
}
};
                        geocoder.getLocations(address, function(json){
                         /* Parse JSON objects */
jJSON["accuracy"] = (function() {
response = {
values: [],
count: 0
};
$.each(json.name.placemark,function(i,item) {
if (placemark.accuracy != "undefined") {
response.count++;
response.values[i] = placemark.accuracy;
}
});
return response;
})();
[/code]
anybody see what i've got wrong here? or if there is another better
way to do this?




























































































    • Topic Participants

    • pete