JSON.parse 错误 #1132:JSON 解析输入无效(Flex / Actionscript / PHP)


JSON.parse Error #1132: Invalid JSON parse input (Flex / Actionscript / PHP)

>我收到"错误 #1132:JSON 解析输入无效",无法理解原因。

我的json是由php:json_encode($x(生成的。输出 json 如果显示在 TextArea(flex( 中,则显示以下内容:

{
   "title":"The Incredibles",
   "year":"2004",
   "type":"movie",
   "id":"9806",
   "imdb_id":"tt0317705",
   "rating":8.6,
   "tagline":"No gut, no glory",
   "overview":"Bob Parr has given up his superhero days to log in time as an insurance adjuster and raise his three children with his formerly heroic wife in suburbia. But when he receives a mysterious assignment, it'''s time to get back into costume.",
   "runtime":115,
   "budget":92000000,
   "image":"http:'/'/cf2.imgobject.com'/t'/p'/w185'/jjAgMfj0TAPvdC8E5AqDm2BBeYz.jpg",
   "trailer":"rMfrFG_69zM"
}

我用几个验证器进行了验证,他们都说这是有效的 json。

在弹性方面,我正在尝试使用以下代码访问 json:

JSON.parse(event.result.toString());

但得到错误。有人遇到过这个问题吗?

编辑 1:

似乎概述线是问题所在,但我不明白为什么,因为我使用了 php json_encode,它应该正确逃避事情......

''' 的转义序列似乎终止了 JSON。

如果你想要"它是",it'''s应该是it''s的。

由于此 JSON 对字符串使用 ",因此它可能只是:it's .

杰森:

{
   "title":"The Incredibles",
   "year":"2004",
   "type":"movie",
   "id":"9806",
   "imdb_id":"tt0317705",
   "rating":8.6,
   "tagline":"No gut, no glory",
   "overview":"Bob Parr has given up his superhero days to log in time as an insurance adjuster and raise his three children with his formerly heroic wife in suburbia. But when he receives a mysterious assignment, it''s time to get back into costume.",
   "runtime":115,
   "budget":92000000,
   "image":"http:'/'/cf2.imgobject.com'/t'/p'/w185'/jjAgMfj0TAPvdC8E5AqDm2BBeYz.jpg",
   "trailer":"rMfrFG_69zM"
}
不知道

你是否已经解决了这个问题,但是我也遇到了同样的问题,今天终于解决了,问题是服务器端,返回json字符串的文件是UTF8编码,我已经将其(通过记事本++(转换为ANSI,一切正常(((。

JSON 没有问题,我知道这个问题已经有了答案,但这个答案适用于那些仍然面临以下错误消息的人:

语法错误:

错误 #1132:JSON 分析输入无效。

当涉及到HTTPService选项时,这可能是结果格式不合适的问题:尝试texte4x格式(它们是最方便的格式(,并避免使用xml格式,这可能会在 JSON 输出中引入一些额外的字符,从而触发一些错误。

使用以下

方法分析数据:

var temp_obj:Object = JSON.parse(event.result as String);

并通过使用正确的resultFormat调用HTTPService来触发 JSON 输出:

resultFormat="text"

resultFormat="e4x"

您的 JSON 是有效的,并且没有任何概率。也许这会对你有所帮助。 在结果事件中,使用以下参考更新代码。

    // Code
    var result:Object = JSON.parse( String(event.result) );
    trace( result['title'] );