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.

1
  • can u give ur url name Commented Feb 19, 2014 at 11:17

3 Answers 3

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"]);

}
Sign up to request clarification or add additional context in comments.

Comments

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];

Comments

0

This is duplicate of this

In short: Use NSJSONSerialization class and check NSDictionary

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.