为什么这个JSON无效?

时间:2014-06-06 09:11:46

标签: iphone json jsonlint

{
    "already_public": "null",
    "status": "true",
    "message": "Service provider added successfully",
    "detail": {
        "id": "1175",
        "address_1": "",
        "address_2": "",
        "profession": "Accountant",
        "city": "",
        "company": "",
        "email_1": "",
        "email_2": "",
        "firstname": "das\' feet",
        "lastname": "",
        "life_block": "Family",
        "work_phone": "",
        "mobile_phone": "",
        "home_phone": "",
        "fax": "",
        "state": "",
        "title": "",
        "website": "",
        "zip": "",
        "ismyprovider": "1",
        "privacy": "null",
        "img_url": "http://localhost/mtube/uploads/blank_pic.png"
    },
    "inresponseto": "addServiceProvider"
}

除了这一行

之外,一切都很好
"firstname": "das\' feet"

双引号内有单引号。尽管在角色之前有一个\,但这个json被jsonlint无效。

3 个答案:

答案 0 :(得分:1)

应该有双斜杠来逃避斜杠char

"firstname": "das\\' feet"

答案 1 :(得分:1)

单引号'不应转义:

  

enter image description here

     

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

     

JSON.org

如您所见,单引号不应转义。

或者如果你想保留\,你需要逃避:

 "firstname": "das\\' feet",

答案 2 :(得分:0)

您无需逃避单引号。更多信息是here