JSON错误:期待'STRING'

时间:2015-06-08 15:08:21

标签: json

[
    {
        votes: "3449",
        title: "The Martian | Official Trailer [HD] | 20th Century FOX",
        post_url: "https://www.youtube.com/watch?v=Ue4PCI0NamI",
        inner_url: "https://www.reddit.com/r/movies/comments/390vcp/the_martian_official_trailer_hd_20th_century_fox/"
    },
    {
        votes: "4582",
        title: "The Easter Island heads have detailed bodies",
        post_url: "http://imgur.com/a/vDFzS",
        inner_url: "https://www.reddit.com/r/pics/comments/390cfz/the_easter_island_heads_have_detailed_bodies/"
    }
]

第2行有问题,但我上面的json没有看到任何问题。

1 个答案:

答案 0 :(得分:3)

您可以使用http://jsonlint.com/等工具检查JSON。

在您的情况下,问题是您没有将您的密钥名称放在引号中。与Javascript不同,JSON需要它(与JavaScript不同,JSON只允许在键和字符串周围使用双引号,而不是单引号)。

你的JSON看起来像这样:

[
    {
        "votes": "3449",
        "title": "The Martian | Official Trailer [HD] | 20th Century FOX",
        "post_url": "https://www.youtube.com/watch?v=Ue4PCI0NamI",
        "inner_url": "https://www.reddit.com/r/movies/comments/390vcp/the_martian_official_trailer_hd_20th_century_fox/"
    },
    {
        "votes": "4582",
        "title": "The Easter Island heads have detailed bodies",
        "post_url": "http://imgur.com/a/vDFzS",
        "inner_url": "https://www.reddit.com/r/pics/comments/390cfz/the_easter_island_heads_have_detailed_bodies/"
    }
]