![](/img/trans.png)
[英]JSON Parse error: Unexpected identifier "undefined" with localStorage
[英]JSON Parse error: Unexpected identifier "undefined"
我今天刚切换到 mac,我注意到在其他浏览器上工作的 JSON.parse,在 safari 上抛出了这个错误。
Unhandled Promise Rejection: SyntaxError: JSON Parse error: Unexpected identifier "undefined"
这是我的 PHP 代码的 JSON 响应
{"dataPointsX": "[\"31 Jan\",\"01 Feb\",\"02 Feb\",\"03 Feb\",\"04 Feb\",\"05 Feb\",\"06 Feb\"]", "dataPointsY": "[\"0\",\"0\",\"7287\",\"24572\",\"30657\",\"27865\",\"0\"]", "dataPoints2Y": "[\"0\",\"0\",\"0\",\"0\",\"0\",\"0\",\"0\"]"}
这是我的 Javascript 代码
$.get('chartdata.php', async function (res) {
console.log(res)
var res = JSON.parse(res);
});
请帮忙
看起来您的 PHP 代码是 JSON 编码的内容,已经进行了 JSON 编码,可能是这样的:
$points = ['31 Jan', '01 Feb', '03 Feb'];
echo json_encode(['dataPointsX' => json_encode($points)]);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.