简体   繁体   English

来自 php 的 json_encode 问题的 JSON.parse

[英]JSON.parse from php's json_encode issue

Running an issue with parsing JSON recieved from php backend.解析从 php 后端收到的 JSON 时出现问题。 On php i have an array, which i send by json_encode:在 php 上,我有一个数组,我通过 json_encode 发送:

$result[] = (object) array('src' => "{$mergedFile}", 'thumb_src' => "{$thumb_file}");
echo json_encode($result);

And when trying to JSON.parse it i recieve error:当尝试 JSON.parse 时,我收到错误:

"Uncaught SyntaxError: Unexpected token F"

The response itself looks this like:响应本身如下所示:

[{"src":"upload\/lessons\/963\/video\/176481500-m.webm","thumb_src":"upload\/lessons\/963\/slide\/thumb_0f515a62753626e1aaefdc7968e8103e.jpg"}]

Very strange thing is that, similar code works nearby.. looks fine.. Appreciate any help, thanks.非常奇怪的是,类似的代码在附近工作.. 看起来不错.. 感谢任何帮助,谢谢。

You cannot JSON.parse() JSON, the param must be a string :你不能JSON.parse() JSON,参数必须是一个字符串:

JSON.parse('[{"src":"upload\/lessons\/963\/video\/176481500-m.webm","thumb_src":"upload\/lessons\/963\/slide\/thumb_0f515a62753626e1aaefdc7968e8103e.jpg"}]');

the error you receive can easily be reproduced by :您收到的错误可以通过以下方式轻松重现:

JSON.parse([{"src":"upload\/lessons\/963\/video\/176481500-m.webm","thumb_src":"upload\/lessons\/963\/slide\/thumb_0f515a62753626e1aaefdc7968e8103e.jpg"}]);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM