Christopher Hannah
Christopher Hannah

Reputation: 1748

How to parse this

I'm experimenting with googles url shortener goo.gl and at the moment it send the url to goo.gl and returns this:

{
 "kind": "urlshortener#url",
 "id": "http://goo.gl/kyPI",
 "longUrl": "http://dsfsd.com/"
}

I think it's JSON but I'm having trouble with that because of ARC. Is there anyway else I could parse the string with key "id"?

Upvotes: 0

Views: 151

Answers (2)

il-os
il-os

Reputation: 203

If your app targets iOS 5 you can use NSJSONSeralization class of Apple.

(Let's assume youryour received is called theData)

NSError *error=nil;
    id result=[NSJSONSerialization JSONObjectWithData:theData options:
               NSJSONReadingMutableContainers error:&error];

//to retrieve the 'kind' value of the object
    NSLog("Kind: %@",[result objectForKey:@"kind"]);

Upvotes: 2

JiaYow
JiaYow

Reputation: 5227

It's JSON, you can use a framework like SBJson to parse it. See http://stig.github.com/json-framework/

Upvotes: 2

Related Questions