{
"category_id" = 1;
fullname = "Wiadomo\U015bci";
name = wiadomosci;
"page_index" = 0;
"show_live" = 1;
},
{
"category_id" = 2;
fullname = Kultura;
name = kultura;
"page_index" = 1;
"show_live" = 0;
},
{
"category_id" = 3;
fullname = Rozrywka;
name = rozrywka;
"page_index" = 2;
"show_live" = 0;
},
{
"category_id" = 4;
fullname = Biznes;
name = biznes;
"page_index" = 3;
"show_live" = 0;
}
我有两个数组,包含category_id,全名,name和page_index。 怎么办?
我使用了AFnetworking:
self.manager = [AFHTTPRequestOperationManager manager];
[self.manager setRequestSerializer:[AFHTTPRequestSerializer serializer]];
self.manager.responseSerializer = [AFJSONResponseSerializer serializer];
[self.manager GET:@"http://webapi.test.pl/newsCategoriesForMobileApp/iphone" parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error);
}];
我不知道如何解析json。
答案 0 :(得分:1)
您已经有了一系列词典,您需要执行以下操作
for(NSDictionary *dic in jsonArray){
NSLog(@"%@, %@, %@",[dic objectForKey:@"category_id"],[dic objectForKey:@"fullname"],[dic objectForKey:@"page_index"]);
}
答案 1 :(得分:0)
如果这个数组名为array。你可以通过
获得财产NSDictionary *dictionary = [array objectAtIndex:page_index];
NSString *fullname = [NSString stringWithFormat:@"%@", [dictionary objectForKey:@"fullname"]];
NSInteger category_id = [[dictionary objectForKey:@"category_id"] integerValue];
答案 2 :(得分:0)
这是this
的副本简而言之: 使用NSJSONSerialization class 并检查NSDictionary