0

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.

4
  • 1
    That'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. Commented Sep 12, 2014 at 14:00
  • but that is created by json_encode. Commented Sep 12, 2014 at 14:06
  • No, it's certainly not. Two alternatives: How to parse this json with php? Commented Sep 12, 2014 at 14:08
  • ok thanks your answer validated my json Commented Sep 12, 2014 at 14:13

1 Answer 1

2

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/

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.