简体   繁体   中英

Why is this JSON invalid?

{
    "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"
}

Everything is ok except for this line

"firstname": "das\' feet"

It has a single quote within double quote. Despite having a \\ before the character this json is being invalidated by jsonlint.

应该有双斜杠来逃脱斜杠字符

"firstname": "das\\' feet"

The single quote ' shouldn't be escaped:

在此处输入图片说明

A string is a sequence of zero or more Unicode characters, wrapped in double quotes, using backslash escapes. A character is represented as a single character string. A string is very much like a C or Java string.

JSON.org

As you can see, the single quote shouldn't be escaped.

Or if you want to keep the \\ , than you need to escape that:

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

You do not need to escape single quote. More info is here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM