Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS Build a Weather App with Swift (Retired) Pulling Data From the Web JavaScript Object Notation

Paul Yorde
Paul Yorde
10,497 Points

Why am I getting something other than JSON from my API response?

Instead of using the weather API, I am using a movie database API. I am getting back a response, however I am getting something that isn't JSON. According to their API, they only support JSON, and since this video is using JSONSerialization, I'm at a loss as to why the response isn't in JSON format.

The Response:

{
    adult = 0;
    "backdrop_path" = "<null>";
    "belongs_to_collection" = "<null>";
    budget = 0;
    genres =     (
    );
    homepage = "<null>";
    id = 299076;
    "imdb_id" = tt0091345;
    "original_title" = "King of Sex";
    overview = "<null>";
    popularity = 0;
    "poster_path" = "<null>";
    "production_companies" =     (
    );
    "production_countries" =     (
                {
            "iso_3166_1" = US;
            name = "United States of America";
        }
    );
    "release_date" = "1986-01-01";
    revenue = 0;
    runtime = "<null>";
    "spoken_languages" =     (
                {
            "iso_639_1" = en;
            name = English;
        }
    );
    status = Released;
    tagline = "<null>";
    title = "King of Sex";
    "vote_average" = 0;
    "vote_count" = 0;
}

3 Answers

Paul Yorde
Paul Yorde
10,497 Points

Well, it looks a lot like JSON, and it may be. However, from what I've found in documentation, JSON doesn't use parentheses, or semi-colons as the code above is doing. JSON would use curly braces for objects, square brackets for arrays and commas as the delimiter.

sunil prakash
sunil prakash
4,323 Points

the above response is surely not JSON, = , () or ; are not part of JSON data.

Michael Hulet
Michael Hulet
47,912 Points

To a semi-trained eye, that response does, in fact, appear to be JSON. The problem must be somewhere in your code. I'm not experienced enough in Swift to help you out, but if you post your code, I'm sure someone around here will be