In the code below, the JSON in the $datastring variable passes as valid JSON on JSONLint.
However, I get Syntax error when using PHP's json_encode.
What can I do to fix this? I've tried stripping the slashes but get same error.
$datastring = '[{"Program": 3034370,"Column": "CLI_RID","Value": "1006278"},{"Program": 3034370,"Column": "Filename","Value": "\\\\henery\\1006278\\CONFIRMATION LETTER AVAILABLE.html"},{"Program": 3034370,"Column": "EVENT_CODE","Value": "20120725ZZAQ"},{"Program": 3034370,"Column": "DOC_NAME","Value": "Confirmation Email"},{"Program": 3034370,"Column": "PrintDate","Value": "20120410"},{"Program": 2959623,"Column": "ISSUE","Value": "Res Spring"},{"Program": 2959623,"Column": "FILENAME","Value": "~/Res/Mag.aspx?I=res_spring&P=1006278"}]';
$data = json_decode($datastring, true);
// Define the errors.
$json_errors = array(
JSON_ERROR_NONE => 'No error has occurred',
JSON_ERROR_DEPTH => 'The maximum stack depth has been exceeded',
JSON_ERROR_CTRL_CHAR => 'Control character error, possibly incorrectly encoded',
JSON_ERROR_SYNTAX => 'Syntax error',
);
if(!$data) {
echo 'Last error : '. $json_errors[json_last_error()]. PHP_EOL. PHP_EOL;
} else {
echo print_r($data, true);
}
I will be getting this JSON string from an ASP.Net page.