jquery.parseJSON无效

时间:2012-05-04 11:51:37

标签: jquery

我的一个函数返回以下字符串:

{
   "data": [{
      "type": "facebook",
      "id": "639422616",
      "name": "Neal Cabage",
      "message": "Ruby on rails or Sinatra better for a restful app that speaks json, not html?"
   }, {
      "type": "facebook",
      "id": "100001604824773",
      "name": "Christolle Soragee",
      "message": "When you lose: "
      Who cares ? !It 's just a game!" When you win: "HAHAHA IN YOUR FACE LOSER!""},{"type":"facebook","id":"100000049925091","name":"Chris Cassanova Dunphy","message":"It'
      s sad when you already know you 're gonna get ripped off and you have to junkie proof your stash... Hahaha good thing I was on point! It'
      s funny how people with a problem will ruin a good thing just "}]}

当我使用jQuery.parseJSON(response)时,如果邮件在邮件中有双引号,则会在某些情况下抛出异常。

非常感谢任何帮助或建议。

由于

1 个答案:

答案 0 :(得分:1)

根据json.org

  

字符串是零个或多个Unicode字符的序列,用双引号括起来,使用反斜杠转义。字符表示为单个字符串。字符串非常类似于C或Java字符串。

String

因此,字符串中的"等字符需要\进行转义,结果类似于"This is my string with a quote \" inside it"