2013-03-21 57 views
0

我有一個包含Json數據的字典。我無法處理它裏面的數據。我試着枚舉,但一直失敗。訪問字典中的json內容

This is the data format I am getting back using NSLog: 

2013-03-21 12:48:36.973 SaleItems[21009:c07] { 
    article = "Surface's other shoe is about to drop: the full Windows 8, Intel Core-driven Surface is headed to stores in just a few weeks."; 
    id = 2; 
    title = "Microsoft Surface Pro hits U.S. and Canada "; 
} 
2013-03-21 12:48:36.974 SaleItems[21009:c07] { 
    article = "Hit by growing demand for Samsung devices, the iPhone will lose smartphone market share for the current quarter, says a Citi analyst"; 
    id = 3; 
    title = "iPhone to shed market share"; 
} 
2013-03-21 12:48:36.974 SaleItems[21009:c07] { 
    article = "The carrier says it plans to buy wireless spectrum and network assets from Atlantic Tele-Network, aka Alltel, in an effort to boost its spectrum coffers."; 
    id = 4; 
    title = "AT&T spends $780 million "; 
} 

我知道從它的外觀我回來的數組字典。我如何訪問其中的數組和元素?

回答

2

看起來你有鑰匙的文章,ID和標題,只需訪問對象中環路:

* 我假設你有一個名爲SalesItem類和上面的日誌是從每個對象那

for(SalesItem *object in SalesItem){ 
    NSLog(@"Article : %@",object[@"article"]); 
    NSLog(@"Id : %@",object[@"id"]); 
    NSLog(@"Title : %@",object[@"title"]); 
} 
+0

非常感謝。工作的確如此 – 2013-03-21 10:03:42

0

這意味着你想要JSON解析。

可以用戶this鏈接,告訴您如何在iOS5中和上述解析JSON。

所有最好的!

+0

如果你絕對需要iOS 4.3,請使用JSONKit或SBJSON – 2013-03-21 10:08:13