[Developers] json_decode issue
Vivek Puri
vp at startupsquad.com
Tue Sep 9 19:11:07 UTC 2008
Chris,
Looking up the php doc for json_decode, i found only couple of things of
relevance.
1. The document states: This function(json_decode) will return false if
the JSON encoded data is deeper than 127 elements.
2. And from one of the comments on the page
"Take care that json_decode() returns UTF8 encoded strings, whereas PHP
normally works with iso-8859-1 characters.
If you expect to receive json data comprising characters outside the
ascii range, be sure to use utf8_decode to convert them:
$php_vlaues = utf8_decode(json_decode($somedata))"
However for me, the json_decode($somedata) itself is a null. Anyhow i
will try adding the utf8_decode later today.
Also, i am pretty sure i am getting results from the API call to freebase.
Actually i make the API call using Bungeeconnect.com. Since Bungeeconnect
does not have a native json parser, i send the data over to my php
script(that includes couple of function calls including json_decode being
the first) via a POST request. This script then sends me back the data in
xml format, which i then use in my app. So yeah, i log the response from
Freebase in Bungeeconnect and know data is coming in.
Vivek
On Tue, Sep 9, 2008 at 11:08 AM, Christopher R. Maden <crism at metaweb.com>wrote:
> Vivek Puri wrote:
> > I am fetching data from freebase and running it through my php script.
> > The php script performs json_decode <http://us.php.net/json_decode> of
> > the json output from freebase. On almost all the data i fetch, it works
> > just fine, except for the following API call:
> >
> > '{"query":{ "query" : [ { "album" : [ { "/common/topic/image" : [ {} ],
> > "length" : null, "id" : null, "name" : null, "sort" : "name",
> > "release_date" : null, "track" : [] } ], "name~=" : "Nusrat Fateh Ali
> > Khan", "type" : "/music/artist" } ] }}'
> >
> > In the above case when i do the json_decode, i get output as null. Any
> > ideas what might be causing that? My php version is 5.2.3
>
> The query seems to run just fine; the only possible problem I can think
> of is that PHP's decoder doesn't handle UTF-8 text. One of those albums
> has a French title and French track titles with accents; if PHP doesn't
> handle the UTF-8 encoding correctly, it might trip over those. Does the
> decoder have a problem with the results of this query?
>
> {
> "id" : "/guid/9202a8c04000641f8000000002fbf759",
> "name" : null,
> "track" : [],
> "type" : "/music/album"
> }
>
> If not, then it may just be the number of albums here. Are you sure
> you're actually getting a result from that query, and not a time-out?
> If you are, are you sure that PHP's decoder doesn't have some kind of
> size limitation on the input?
>
> ~Chris
> --
> Christopher R. Maden
> Data Architect
> Freebase.com: <URL: http://www.freebase.com/ >
> Metaweb Technologes, Inc. <URL: http://www.metaweb.com/ >
> _______________________________________________
> Developers mailing list
> Developers at freebase.com
> http://lists.freebase.com/mailman/listinfo/developers
>
--
Vivek Puri
GTalk: vp at vivekpuri.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.freebase.com/pipermail/developers/attachments/20080909/40d6b62b/attachment.htm
More information about the Developers
mailing list