开发者

decoding json problem, returns null value

my solution was :

function format_json($str)
  {
    ...
    $str = preg_replace('/([a-z]+):/i', '"$1":', $str);
    $wtr = array('""',',",');
    $rpw = array('"',',');
    return str_replace($wtr开发者_StackOverflow社区, $rpw, $str);
  }


Like stated in previous answers, you need to add double-quote to strings. A really fast and quick way to check json string is to use JSONLint.

Here's the output you will get from JSONLint:

Parse error on line 1:
{    m: [        {     
-----^
Expecting 'STRING', '}'

So you need to change all parts that don't have double quotes. For example:

{m: [ ...

Will become:

{"m": [ ...

Edit after comment: It seems that the double quotes inside strings are not escaped properly. For example:

{"m" : [ { "g": [ "32", "Brezilya-"Serie" A", "83", ...
Here -----------------------------^ and ^

Should be:

{"m" : [ { "g": [ "32", "Brezilya-\"Serie\" A", "83", ...


JSON only supports double-quoted strings, and all of the property names must be quoted.


Try to run your JSON through JSONLint. To begin with, property names must be enclosed in double quotes. Then, strings must also be enclosed in double quotes instead of single quotes:

{
    "m": [
        {
            "g": [
                32,
                "Brezilya-SerieA",
                .
                .
                .


You can parse this string with class from here http://pear.php.net/pepr/pepr-proposal-show.php?id=198

require_once 'JSON.php';
$json = new Services_JSON();
$data = $json->decode($yourstring);


IN your JSON you should use " " instead of ' ' and that will get solved.

its a convention in JSON that the double qoutes will be used to define object names or objects .. try using the way u write a string in C++ for defining your json .

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜