2012-02-26 57 views
0

我與谷歌網址縮短服務goo.gl而且目前試驗其發送的URL的goo.gl並返回此:如何解析這個

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

我認爲這是JSON,但我有由於ARC而引起的麻煩。有沒有其他的我可以用鍵「id」解析字符串?

+1

爲什麼你會被具有ARC和JSON煩惱嗎? – 2012-02-26 15:26:24

+0

由於某些原因,大多數JSON框架總是與ARC搞砸。 – 2012-02-26 15:29:58

+0

NSJSONSerialization內置於ios中,如果外部框架給您帶來麻煩,請使用它。 – jrturton 2012-02-26 15:40:53

回答

2

如果您的應用以iOS 5爲目標,則可以使用NSJSONSeralization類Apple。

(假設youryour收到被稱爲海圖)

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"]);