2013-06-18 109 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中使用内置框架。所以我认为它是可可触摸 –