0

I am new in Handling Response. While trying to fetch Values("title") in array, it is not working properly. It is updating Last Value alone in Array. How can I fetch all values("title") in an array? I even tried changing lastObject as objectAtIndex:

Below is my Response Output and Code.

NSDictionary *book = [[ jsonResults objectForKey:@"result"] lastObject];
NSArray *title = (NSArray *) [book objectForKey:@"title"];

Response Output:

{
    "result":
    [
       {
           "authors": [
                       "AuthRick"
                       ],
           "bno": 9280621999,
           "title": "Foo",
           "urlImage": "www.foo.hoo",
       },{
           "authors": [
                       "MaveRick"
                       ],
           "bno": 9951621988,
           "title": "Hoo",
           "urlImage": "www.foo.hoo",
       }
     ]
}
4

3 回答 3

1

您可以使用以下代码获取标题数组中的所有标题字段值:

NSArray *resultArray = [jsonResults objectForKey:@"result"];
NSMutableArray *title = [NSMutableArray alloc] init];
for(NSDictionary *obj in resultArray)
{
  [arytitle addObject:[obj valueForKey:@"title"]];
}
于 2013-09-17T10:31:10.283 回答
1

当我看到这个时,这可能适合这个反应,

NSMutableArray *titleArray = [[NSMutableArray alloc]init];
NSArray *resultArray = [ jsonResults objectForKey:@"result"];
for(NSDictionary *individualBookDictionary in resultArray)
{
  [titleArray addObject:[individualDictionary valueForKey:@"title"]];
}
于 2013-09-17T10:20:24.710 回答
1
try this..



NSDictionary *response; //getting your response as Dictionary,so keep response dictionary in response variable(i.e response dictionary)

    NSArray *arr =[response valueForKey:@"result"]; //get result Array

    for (int i=0; i<arr.count; i++) {

        NSLog(@"title--%@",[[arr objectAtIndex:i] valueForKey:@"title"]); //here your getting two titles of data


    }
于 2013-09-17T10:20:37.693 回答