JSON.parse:仅在Firefox中JSON数据的第1行第1列出现意外字符 [英] JSON.parse: unexpected character at line 1 column 1 of the JSON data in Firefox only
问题描述
我已经通过PowerShell创建了一个JSON文件并将其放在服务中.
I have create one JSON file through PowerShell and place it on serve.
当我通过 $.getJSON 访问该JOSN文件时,它在crome和IE浏览器中工作正常,但是当我在Firefox中访问该JSON文件时,我得到了错误
When i access that JOSN file through $.getJSON it works fine in crome and IE browser but when i access that JSON file in Firefox i got error of
JSON.parse:JSON数据第1行第1列的意外字符
JSON.parse: unexpected character at line 1 column 1 of the JSON data
标题:
回复:
应该是什么问题以及如何在firefox中修复它?
What should be issue and how to fix it in firefox?
推荐答案
您已经说过服务器使用Content-Type: text/plain
发送回JSON.数据似乎在UTF-16中(可能是基于屏幕截图),但是text/plain
的默认字符集是us-ascii
(请参阅
You've said that the server sends that JSON back with Content-Type: text/plain
. The data appears to be in UTF-16 (probably, that's based on the screenshot), but the default charset for text/plain
is us-ascii
(see §4.1.2 of RFC2046):
4.1.2.字符集参数
4.1.2. Charset Parameter
可以在内容类型"字段中指定的关键参数 对于文本/纯文本"数据是字符集.用一个指定 字符集"参数,如:
A critical parameter that may be specified in the Content-Type field for "text/plain" data is the character set. This is specified with a "charset" parameter, as in:
Content-type: text/plain; charset=iso-8859-1
与其他一些参数值不同,字符集的值 参数不区分大小写.默认字符集,即 必须假定没有字符集参数,即US-ASCII.
Unlike some other parameter values, the values of the charset parameter are NOT case sensitive. The default character set, which must be assumed in the absence of a charset parameter, is US-ASCII.
因此,您需要更改服务器的响应,以使其正确标识正在使用的字符集,例如Content-Type: text/plain; charset=UTF-16
(显然首先要确保实际上就是资源的字符集).
So, you need to change the response from the server such that it correctly identifies the character set being used, e.g. Content-Type: text/plain; charset=UTF-16
(obviously ensuring first that that is, in fact, the charset of the resource).
我只是要指出,从我能从JSON中提取的内容来看,它看起来主要是在西方脚本中.如果是这样,那么UTF-16是不寻常且效率低下的选择,那么使用UTF-8可能会更好.但是我只有一小段文字可以处理.
I'll just note that, from what I can make out of the JSON, it looks like it's primarily in a western script. If so, UTF-16 is unusual and inefficient choice, you'd probably be better off with UTF-8. But I only have a small fragment of the text to work from.
这篇关于JSON.parse:仅在Firefox中JSON数据的第1行第1列出现意外字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!