Elton Jamie
Elton Jamie

Reputation: 584

JSON error: Expecting 'STRING'

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

There's a problem in line 2, but I don't see anything wrong with my json above.

Upvotes: 1

Views: 603

Answers (1)

IvanAtBest
IvanAtBest

Reputation: 2924

You can check a JSON using tools like http://jsonlint.com/.

In your case, the problem is that you are not putting your key names in quotes. Unlike Javascript, JSON requires it (and unlike JavaScript, JSON only allows double quotes around keys and strings, not single quotes).

Your JSON would look like this:

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

Upvotes: 3

Related Questions