Reputation: 2123
I have create one JSON file through PowerShell and place it on serve.
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: unexpected character at line 1 column 1 of the JSON data
Header:
Response:
What should be issue and how to fix it in firefox?
Upvotes: 2
Views: 4000
Reputation: 1075427
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. 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
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.
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).
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.
Upvotes: 1