I have JSON string like:
'"[{\"type\": \"EDITOR\", \"value\": \"fsddfsdsfdfs\"}, {\"type\": \"CITA\", \"value\": \"Bug:\\n\\t\\t\\t\\t\\t0 open / 0\\n\\t\\t\\t\\n \\n Feature:\\n\\t\\t\\t\\t\\t1 open / 1\\n\\t\\t\\t\"}]"'
json_decode fails to decode it.
Removing ” mark from start and end makes it to work
'[{\"type\": \"EDITOR\", \"value\": \"fsddfsdsfdfs\"}, {\"type\": \"CITA\", \"value\": \"Bug:\\n\\t\\t\\t\\t\\t0 open / 0\\n\\t\\t\\t\\n \\n Feature:\\n\\t\\t\\t\\t\\t1 open / 1\\n\\t\\t\\t\"}]'
test code
$test1 = '"[{"type": "EDITOR", "value": "fsddfsdsfdfs"}, {"type": "CITA", "value": "Bug: 0 open / 0 Feature: 1 open / 1 "}]"';
print_r(json_decode($test1));
echo json_last_error().'<br>';
$test2 = '[{"type": "EDITOR", "value": "fsddfsdsfdfs"}, {"type": "CITA", "value": "Bug: 0 open / 0 Feature: 1 open / 1 "}]';
print_r(json_decode($test2));
Am I missing something or using it wrong?
You should not call your string a “JSON string”, because it is none. You surely did not get this string using json_encode(). The grammar for JSON has only two top-level productions:
It follows that: