在下面的代码中,$datastring 变量中的 JSON 作为 JSONLint 上的有效 JSON 传递。
但是,使用 PHP 的 json_encode 时出现语法错误。
我能做些什么来解决这个问题?我试过剥离斜线但得到同样的错误。
$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);
}
我将从 ASP.Net 页面获取此 JSON 字符串。