Search code examples
iosobjective-cnsarraynsdictionary

iOS: How can I get value from object which is inside an array, which is inside one dictionary?


I am getting a JSON like this:

{
    response =  {
        message = (
            "Permission denied, you do not have permission to access the requested page."
        );
    };
}

I want to print:

"Permission denied, you do not have permission to access the requested page."

How can I get the value?


Solution

  • In Objective C

     NSArray *arrRes = [[jsonRes objectForKey:@"response"] objectForkey:@"message"];
     NSLog(@"The output result is - %@",arrRes);
    

    Then if you want to print the string from the array do like below

    for(int i=0;i<arrRes.count;i++){
            NSString *strRes = arrRes[i];
            NSLog(@"The strRes is - %@",strRes);
    }