Search code examples
objective-cjsoncallbackresponsetumblr

Parsing callback response from Tumblr


How can I parse the tumblr response in order to retrieve items such as the photo link, title etc. According to Tumblr API, it's in JSON format but I can't seem to understand how to code it. Here a snippet of the response:

{ 
    "blog_name" = myBlogName;
    "can_reply" = 0;
    caption = "<p>pending again</p>";
    date = "2014-01-19 15:54:22 GMT";
    followed = 0;
    format = html;
    highlighted = ();
    id = 73836876344;
    "image_permalink" = "http://bantaybayan.tumblr.com/image/73836876344";
    liked = 0;
    "note_count" = 0;
    photos =         (
                    {
            "alt_sizes" =                 (
                                    {
                    height = 558;
                    url = "http://24.media.tumblr.com/f3fc43d081e3a6366e794b4f94a82d37/tumblr_mzno6mMXgr1tnzku0o1_1280.jpg";
                    width = 740;
                },
                                    {
                    height = 377;
                    url = "http://31.media.tumblr.com/f3fc43d081e3a6366e794b4f94a82d37/tumblr_mzno6mMXgr1tnzku0o1_500.jpg";
                    width = 500;
                },
                                    {
                    height = 302;
                    url = "http://24.media.tumblr.com/f3fc43d081e3a6366e794b4f94a82d37/tumblr_mzno6mMXgr1tnzku0o1_400.jpg";
                    width = 400;
                },
                                    {
                    height = 189;
                    url = "http://25.media.tumblr.com/f3fc43d081e3a6366e794b4f94a82d37/tumblr_mzno6mMXgr1tnzku0o1_250.jpg";
                    width = 250;
                },
                                    {
                    height = 75;
                    url = "http://31.media.tumblr.com/f3fc43d081e3a6366e794b4f94a82d37/tumblr_mzno6mMXgr1tnzku0o1_100.jpg";
                    width = 100;
                },
                                    {
                    height = 75;
                    url = "http://31.media.tumblr.com/f3fc43d081e3a6366e794b4f94a82d37/tumblr_mzno6mMXgr1tnzku0o1_75sq.jpg";
                    width = 75;
                }
            );
            caption = "";
            "original_size" =                 {
                height = 558;
                url = "http://24.media.tumblr.com/f3fc43d081e3a6366e794b4f94a82d37/tumblr_mzno6mMXgr1tnzku0o1_1280.jpg";
                width = 740;
            };
        }
    );
    "post_url" = "http://bantaybayan.tumblr.com/post/73836876344/pending-again";
    "reblog_key" = LUOtTeAe;
    "short_url" = "http://tmblr.co/Z89Zxo14n1L8u";
    slug = "pending-again";
    state = published;
    tags =         (
    );
    timestamp = 1390146862;
    type = photo;
}

Thanks in advance


Solution

  • First of all, this doesn't look like JSON. Check it with a validator like JSONLint

    It's easier if you use an editor for JSON data. There a lots of free online services http://jsoneditoronline.org/

    For Objective-C, this SO question might help you out: Parsing JSON using Objective-C