开发者

Trying to parse a JSON string, but always fails

开发者_如何转开发This piece of JSON right here:

{"user":[{"idUser":"1","username":"USERNAME","userFullName":"FULL NAME","userEmail":"EMAIL@MAIL.COM"}]}

Does not validate in jsonlint also not with GWT.

What is strange is that if I delete the first curly brace and type it again, it returns as valid. Here is the error it gives:

Parse error on line 1:
{    "user": [   
^
Expecting '{', '['

Any reason for this? Note that I'm using PHP to generate this string. PHP file used is UTF-8 encoded.


When I copy/paste that into JSONLint, it passes.

You did something else wrong.


Thanks to @knittl for noticing it.

I had the php file encoded in UTF-8.

I changed it to UTF-8 without BOM and it worked. I suppose some "garbage" was being returned when I was copying it to jsonlint.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜