简体   繁体   English

解析具有逗号和引号的JSON文本

[英]Parsing JSON text having comma and quotation marks

I got an "Parse error" on the following JSON object. 我在以下JSON对象上得到了“Parse错误”。 Wonder how to fix it. 不知道如何解决它。

 { "Information": [ { "nm": "Earn Goody", "st": "y", "source": "Internet", "story": [ { "Don't let the smile fool you. Sabine Lisicki is the proverbial "crazy guy in the fight," at least when grass courts are involved. Perhaps the only player capable of keeping up with Serena Williams from a power-and-movement standpoint, Lisicki not only kept up, she beat Williams, 6-2, 1-6, 6-4, in the Round of 16 at Wimbledon on Monday.", "Women's tennis had, like men's tennis, grown predictable recently, with either Williams, Maria Sharapova, or Victoria Azarenka winning the last six slam titles." } ] } ] } 

Result: 结果:

{
    "Information": [
        {
            "nm": "Earn Goody",
            "st": "y",
            "source": "Internet",
            "story": [
                {
                    "Don't let the smile fool you. Sabine Lisicki is the proverbial crazyguyinthefight at least when grass courts are involved. Perhaps the only player capable of keeping up with Serena Williams from a power-and-movement standpoint, Lisicki not only kept up, she beat Williams, 6-2, 1-6, 6-4, in the Round of 16 at Wimbledon on Monday.",
                    "Women's tennis had, like men's tennis, grown predictable recently, with either Williams, Maria Sharapova, or Victoria Azarenka winning the last six slam titles."
                }
            ]
        }
    ]
}

Parse error on line 9:
...imbledon on Monday.",                  
-----------------------^
Expecting ':'

The "JSON" data string at Information[0]/story[0] contains unescaped quotes ( " ). That's not valid JSON. Information[0]/story[0]中的“JSON”数据字符串包含未转义的引号( " )。这不是有效的JSON。

Somewhere around here: . 在这附近:。 . . proverbial "crazy guy in the fight," at least . proverbial "crazy guy in the fight," at least . .

The quotes inside of your data string should instead be escaped ( \\" ). 应该转义数据字符串中的引号( \\" )。

Like this: . 像这样: 。 . . proverbial \\"crazy guy in the fight,\\" at least . proverbial \\"crazy guy in the fight,\\" at least . .

Furthermore , the story[0] JSON object contains fields without names - also invalid. 此外story[0] JSON对象包含没有名称的字段 - 也无效。 You can just put a JSON string inside of curly brackets ( { "abc" } ). 您可以将JSON字符串放在大括号内( { "abc" } )。 A JSON object is a collection of key-value pairs where they key is a JSON string ( { "some-key": "abc" } ). JSON对象是键值对的集合,其键是一个JSON字符串( { "some-key": "abc" } )。

In general, refer to here: http://json.org/ 一般来说,请参考: http//json.org/

You probably want the story array to contain string values? 您可能希望故事数组包含字符串值? in that case, remove the curly barces "{}" inside the array. 在这种情况下,删除数组内的花键“{}”。

The other comments on the quoting also apply, but the error message is related to the invalid array format. 关于引用的其他注释也适用,但错误消息与无效的数组格式有关。 See JSON.org JSON.org

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

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