2013-06-18 186 views
0

我正在解析我的應用程序從Wordpress接收的帖子。我正在獲取數據。我把它放在字典裏。唯一的問題是我目前收到7個帖子。以下是我從服務器獲得的內容。解析JSON時從「元素」中獲取特定「元素」

status": "ok", 
"count": 7, 
"count_total": 7, 
"pages": 1, 
"posts": [ 
{ 
    "id": 125, 
    "type": "post", 
    "slug": "michaela-hi", 
    "url": "http:\/\/www.garytournaments.com\/2013\/06\/18\/michaela-hi\/", 
    "status": "publish", 
    "title": "Test Posts", 
    so on and so on..till the next post 
    "id": 117, 
    "type": "post", 
    "slug": "may-4th-tournament", 
    "url": "http:\/\/www.garytournaments.com\/2013\/04\/29\/may-4th-tournament\/", 
    "status": "publish", 
    "title": "May 4th Tournament", 
    "title_plain": "May 4th Tournament 

    repeat; 

我的問題是「身份證,slu,等」是所有的帖子的價值。我不知道如何提取個人數據以及將數據分解成單獨的帖子

+0

所以posts是你的字典中的一個字典數組,這有什麼問題? – Wain

回答

0

您應該做一些類似下面的循環來處理帖子信息。

NSDictionary *myDict = ...; // from word press 
NSArray *posts = [myDict objectForKey:@"posts"]; 

for (NSDictionary *postDict in posts) { 
    NSLog(@"post id: %@", [postDict objectForKey:@"id"]); 
} 
0

職位的值是字典對象的數組:該數組的每個元素是一個單一的柱,其中所述部分的被分解成鍵 - 值對。讓我問你一些問題:你使用Cocoa-Touch框架支持解析JSON嗎?它會自動將JSON數據轉換爲NSArray和NSDictionary對象。

+0

我在xCode中使用內置框架。所以我認爲它是可可觸摸 –