1

i have a problem. I have to parse this json:

{
        "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;
    }

I have two arrays with category_id, full name, name and page_index. How to do?

I used 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);
    }];

and I'don't know how to parsing json.

wysio90
  • 33
  • 5

3 Answers3

1

You already have array of dictionaries, you need to just do the following

for(NSDictionary *dic in jsonArray){

    NSLog(@"%@, %@, %@",[dic objectForKey:@"category_id"],[dic objectForKey:@"fullname"],[dic objectForKey:@"page_index"]);

}
iphonic
  • 12,615
  • 7
  • 60
  • 107
0

if this array named array. You can get property by

NSDictionary *dictionary = [array objectAtIndex:page_index];
NSString *fullname = [NSString stringWithFormat:@"%@", [dictionary objectForKey:@"fullname"]];
NSInteger category_id = [[dictionary objectForKey:@"category_id"] integerValue];
larva
  • 4,687
  • 1
  • 24
  • 44
0

This is duplicate of this

In short: Use NSJSONSerialization class and check NSDictionary

Community
  • 1
  • 1