Google Groups Home
Help | Sign in
json parser doesn't output
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  1 message - Collapse all
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
pedalpete  
View profile
 More options May 16, 11:39 pm
From: pedalpete <p...@zifimusic.com>
Date: Fri, 16 May 2008 20:39:03 -0700 (PDT)
Local: Fri, May 16 2008 11:39 pm
Subject: 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-javascr...

, 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?


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2008 Google