my json data that names are between ("") is working as following.
var_dump(json_decode('{"a":"foo","b":"bar"}', true));
but names are not between ("") is not working:
var_dump(json_decode('{a:"foo",b:"bar"}', true)) ;
my json data is coming from another server like this:
{a:"foo",b:"bar"}
and that json created by php with json_encode.
$rows = array();
while($r = mysqli_fetch_assoc($sql)) {
$rows[] = $r;
}
return json_encode($rows)
but json_decode returning NULL for this object.
asked Sep 12, 2014 at 13:59
barteloma
6,96516 gold badges95 silver badges216 bronze badges
-
1That's not JSON then, but JavaScript Object Literals (JSOL). PHPs plain json_decode() does not support it. Use a more specific parser, or one of the unreliable patch workarounds.mario– mario2014年09月12日 14:00:44 +00:00Commented Sep 12, 2014 at 14:00
-
but that is created by json_encode.barteloma– barteloma2014年09月12日 14:06:47 +00:00Commented Sep 12, 2014 at 14:06
-
No, it's certainly not. Two alternatives: How to parse this json with php?mario– mario2014年09月12日 14:08:13 +00:00Commented Sep 12, 2014 at 14:08
-
ok thanks your answer validated my jsonbarteloma– barteloma2014年09月12日 14:13:45 +00:00Commented Sep 12, 2014 at 14:13
1 Answer 1
Looks like you will have to modify the string before parsing it because that isn't valid JSON. You can check it with a site like this.
Sign up to request clarification or add additional context in comments.
Comments
lang-php