barteloma
barteloma

Reputation: 6875

PHP json_decode data format

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.

Upvotes: 0

Views: 289

Answers (1)

MrTippet
MrTippet

Reputation: 306

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.

http://jsonlint.com/

Upvotes: 2

Related Questions