简体   繁体   English

"字符串中的无效 JSON 转义序列"

[英]Invalid JSON Escape Sequence in String

I am working with a MySQL db that has encoded polygon for google maps.我正在使用一个为谷歌地图编码多边形的 MySQL 数据库。 When I try to return the query as json, jsonlint complains.. I am not sure why its complaining , I did try escaping the "}" in the latlon but still get the same error.当我尝试将查询返回为 json 时,jsonlint 抱怨.. 我不确定它为什么抱怨,我确实尝试在 latlon 中转义“}”,但仍然得到相同的错误。

Parse error on line 20:
...          "latlon": "}ciuF|a|pNcUr@d@es@
-----------------------^
Expecting 'STRING', 'NUMBER', 'NULL', 'TRUE', 'FALSE', '{', '['

My json is:我的json是:

{
    "maps": [
        {
            "group_id": "0",
            "user_id": "113",
            "group_name": "",
            "note": "",
            "field_id": "",
            "field_name": "West Pasture",
            "field_notes": "",
            "date_created": "12/31/2012",
            "acres": ""
        }
    ],
    "polygon": [
        {
            "polygon_id": "",
            "field_id": "1",
            "acres": "92",
            "latlon": "}ciuF|a|pNcUr@d@es@fIHXaNtCn@UxCjMlApAfFuBpI}E\ChJdEl@xAtE"
        }
    ]
}

The problem is that there is a slash before the C which is not a valid escape sequence.问题是在 C 之前有一个斜线,它不是有效的转义序列。

"}ciuF|a|pNcUr@d@es@fIHXaNtCn@UxCjMlApAfFuBpI}E \\C hJdEl@xAtE" "}ciuF|a|pNcUr@d@es@fIHXaNtCn@UxCjMlApAfFuBpI}E \\C hJdEl@xAtE"

JSON.parse('"\\C"');

This will give you a syntax error because it is trying to parse the string \\C .这会给你一个语法错误,因为它试图解析字符串\\C If you want a literal \\ in your property's value, you need to escape it.如果您想在您的属性值中使用文字\\ ,则需要对其进行转义。

"latlon": "}ciuF|a|pNcUr@d@es@fIHXaNtCn@UxCjMlApAfFuBpI}E\\ChJdEl@xAtE"

The relevant section from the official grammar :官方语法的相关部分:

string
    ""
    " chars "
chars
    char
    char chars
char
    any-Unicode-character-
        except-"-or-\-or-
        control-character
    \"
    \\
    \/
    \b
    \f
    \n
    \r
    \t
    \u four-hex-digits 

Fast way to escape JSON:转义 JSON 的快速方法:

Use this site: https://www.freeformatter.com/json-escape.html使用这个网站: https ://www.freeformatter.com/json-escape.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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