Reputation: 4321
{
"hintsacross":
[ { "number":"1" , "hinttext":"Hurt", "hintsquare":"A1" },
{ "number":"5" , "hinttext":"Make a selection", "hintsquare":"A6" },
{ "number":"8" , "hinttext":"Frank", "hintsquare":"A10" }
] ,
"hintsdown":
[ { "number":"1" , "hinttext":"First Greek letter", "hintsquare":"A1" },
{ "number":"2" , "hinttext":"Used footnotes", "hintsquare":"A2" },
{ "number":"3" , "hinttext":"Listened to", "hintsquare":"A3" }
]
}
For some reason json_decode of PHP is not decoding this JSON.
Thanks in advance...
P.S. I am getting an error when this line 25 runs:
$temp = json_decode( $obj->hints,true );
Parse error: syntax error, unexpected 'hintsacross' (T_STRING) in C:\Program Files (x86)\Zend\Apache2\htdocs\crosswords\query.blockouts.php on line 25
I validated my JSON through JSONlint and the parse error is coming out.
Upvotes: 0
Views: 2470
Reputation: 6938
The json is not in correct format. Use jsonlint.com to check this. You will get the error and if the json format is correct, you will get an okay message as well.
Parse error on line 18:
...A10" } ]"hintsdown": [
---------------------^
Expecting 'EOF', '}', ',', ']'
Correct json :
{
"hintsacross": [
{
"number": "1",
"hinttext": "Hurt",
"hintsquare": "A1"
},
{
"number": "5",
"hinttext": "Make a selection",
"hintsquare": "A6"
},
{
"number": "8",
"hinttext": "Frank",
"hintsquare": "A10"
}
],
"hintsdown": [
{
"number": "1",
"hinttext": "First Greek letter",
"hintsquare": "A1"
},
{
"number": "2",
"hinttext": "Used footnotes",
"hintsquare": "A2"
},
{
"number": "3",
"hinttext": "Listened to",
"hintsquare": "A3"
}
]
}
Upvotes: 1
Reputation: 8144
$ll="{ "hintsacross": [ { "number":"1" , "hinttext":"Hurt", "hintsquare":"A1" }, { "number":"5" , "hinttext":"Make a selection", "hintsquare":"A6" }, { "number":"8" , "hinttext":"Frank", "hintsquare":"A10" } ],
"hintsdown": [ { "number":"1" , "hinttext":"First Greek letter", "hintsquare":"A1" }, { "number":"2" , "hinttext":"Used footnotes", "hintsquare":"A2" }, { "number":"3" , "hinttext":"Listened to", "hintsquare":"A3" } ] } "
$ll = json_decode($ll);
print_r($ll);
add (,) comma near
],
"hintsdown"
hope this will help
Upvotes: 1
Reputation: 10094
It is invalid JSON. Try adding a comma before "hintsdown" and retrying the json_decode.
{
"hintsacross": [
{
"number": "1",
"hinttext": "Hurt",
"hintsquare": "A1"
},
{
"number": "5",
"hinttext": "Make a selection",
"hintsquare": "A6"
},
{
"number": "8",
"hinttext": "Frank",
"hintsquare": "A10"
}
],
"hintsdown": [
{
"number": "1",
"hinttext": "First Greek letter",
"hintsquare": "A1"
},
{
"number": "2",
"hinttext": "Used footnotes",
"hintsquare": "A2"
},
{
"number": "3",
"hinttext": "Listened to",
"hintsquare": "A3"
}
]
}
Upvotes: 5