开发者

Trouble on parsing JSON data

What is wrong in parsing following JSON data

'{
   {"errors":
     {"firstname":"is too short"}
   },
   {"account":
     {"firstname":"Test"}
   }
}'

for which a get this error?

JSON::ParserError in AccountsCont开发者_运维问答roller#home
706: unexpected token at ... # the code above

?

In the AccountsController I have

JSON.parse(json_data)["errors"]


You should not encapsulate the attribute errors and account. It should probably look like this:

'{
  "errors":{"firstname":"is too short"},
  "account":{"firstname":"Test"}
}'


You're missing property names:

'{"property1":
   {"errors":
     {"firstname":"is too short"}
   },
  "property2":
   {"account":
     {"firstname":"Test"}
   }
}'

Or, you really wanted an array:

'[
   {"errors":
     {"firstname":"is too short"}
   },
   {"account":
     {"firstname":"Test"}
   }
]'


Your data struct appears to be a JSON object {} but you have an array []. The first set of {} should be [].

http://www.jsonlint.com/

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜