簡體   English   中英

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

[英]Parsing JSON text having comma and quotation marks

我在以下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 ':'

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/

您可能希望故事數組包含字符串值? 在這種情況下,刪除數組內的花鍵“{}”。

關於引用的其他注釋也適用,但錯誤消息與無效的數組格式有關。 JSON.org

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM