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

时间:2013-07-01 17:48:55

标签: json

我在以下JSON对象上遇到了“Parse错误”。不知道如何解决它。

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

结果:

{
    "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 ':'

2 个答案:

答案 0 :(得分:1)

Information[0]/story[0]处的“JSON”数据字符串包含未转义的引号(")。这不是有效的JSON。

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

您的数据字符串中的引号应该被转义(\")。

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

此外story[0] JSON对象包含没有名称的字段 - 也无效。您可以将JSON字符串放在大括号({ "abc" })中。 JSON对象是键值对的集合,其键是一个JSON字符串({ "some-key": "abc" })。

一般情况下,请参阅此处:http://json.org/

答案 1 :(得分:1)

您可能希望故事数组包含字符串值?在这种情况下,删除数组中的花键“{}”。

引用的其他注释也适用,但错误消息与无效的数组格式有关。见JSON.org