-1

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

{
   "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)时,在某些情况下,当消息在消息中包含双引号时,它会引发异常。

任何帮助或建议将不胜感激。

谢谢

4

1 回答 1

1

根据json.org

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

细绳

因此,"字符串中的字符需要用 a 转义\,从而变成类似"This is my string with a quote \" inside it".

于 2012-05-04T12:02:59.380 回答