if you are using jsonp, then you have to wrap the JSON inside a
function

so for instance, on the docs page they have this Ajax call (and i'll
remove some code for brevity):

$.getJSON(
      "http://api.flickr.com/services/feeds/photos_public.gne?
tags=cat&format=json&jsoncallback=?",
      function(data){
          // Do stuff with json object "data"
      }
);

the actual text generated by Flickr is

jsonp1256221212936({
                "title": "Recent Uploads tagged cat",
                "link": "http://www.flickr.com/photos/tags/cat/";,
                "description": "",
                "modified": "2009-10-22T14:01:57Z",
                "generator": "http://www.flickr.com/";,
                "items": [
           {
                        "title": "a kitteh",
                        "link": 
"http://www.flickr.com/photos/ifido/4034869804/";,
                        "media": {"m":"http://farm3.static.flickr.com/
2778/4034869804_6a838ee975_m.jpg"},
                        "date_taken": "2009-10-21T22:57:02-08:00",
                        "description": "a description",
                        "published": "2009-10-22T14:01:57Z",
                        "author": "nob...@flickr.com (ifido)",
                        "author_id": "30832...@n00",
                        "tags": "red cat paws"
           }
        ]
})



So seeing that working sample, your generated JSON of

{"15":{"id":15,"x":0.4589937586135409,"y":
0.8324914620560137,"z":-0.9435707004102728,"rawData":"1256204002860 13
-442866538 18392602 647462767 314 1777206957 -1664784174 "}}

should be

XXXXXXXX({"15":{"id":15,"x":0.4589937586135409,"y":
0.8324914620560137,"z":-0.9435707004102728,"rawData":"1256204002860 13
-442866538 18392602 647462767 314 1777206957 -1664784174 "}})

Where XXXXXXX is the posted value of the Form key "callback"

*then* getJSON will work   :-)

This article is a fantastic read to understand what is going on with a
jsonp call

http://www.ibm.com/developerworks/library/wa-aj-jsonp1/





On Oct 22, 9:15 am, loste <lapecoracarniv...@gmail.com> wrote:
> Hello,
> I'm trying to parse a Json string received by $.getJSON().
>
> I can receive the string but firebug gives me an "invalid label"
> error.
> I think it is because the string is an hash array with a number as
> first label, but I'm not sure.
>
> This is the string:
> {"15":{"id":15,"x":0.4589937586135409,"y":
> 0.8324914620560137,"z":-0.9435707004102728,"rawData":"1256204002860 13
> -442866538 18392602 647462767 314 1777206957 -1664784174 "}}
>
> and this is the non-working code:
>
>  $.getJSON(url+"&jsoncallback=?", function(received){
>         stateChanged(received);
>     });
>
> Any Idea on how can I import it?
>
> Thank you,
> loste

Reply via email to