-2

这是我的字典结果。

"continent_code" = EU;
"country_code" = gb;
"country_id" = 169;
"country_name" = "United Kingdom";


NSString *responseString = [[NSString alloc] initWithData:responseData      
encoding:NSUTF8StringEncoding];
NSDictionary *LoginResult = (NSDictionary*)[responseString JSONValue];

我只想从字典中检索国家名称到 NSArray。

4

3 回答 3

0

填写countryArray的正确方法:

NSError* error;
NSDictionary* json = [NSJSONSerialization JSONObjectWithData:yourResponseData options:kNilOptions error:&error];
NSArray* getMAS_CR = [(NSDictionary*)json objectForKey:@"yourKeyRootResult"];
NSMutableArray *countryArray = [[NSMutableArray alloc]init];
for (NSDictionary *rr in getMAS_CR)
{
    NSString *cName = [NSString stringWithFormat:@"%@",[rr objectForKey:@"country_name"]];
    [countryArray addObject:cName];
}
NSLog(@"countryArray :: %@",countryArray);

祝你好运。

于 2013-04-17T07:10:43.533 回答
0

尝试这个 ::

NSArray *jsonArray = [NSJSONSerialization JSONObjectWithData:webData options:NSJSONReadingMutableContainers error:&error];

NSLog(@" Value :: %@", [[jsonArray JSONRepresentation] JSONValue]);

for (NSDictionary *item in jsonArray) {
   NSLog(@" Item :::::> %@", [item objectForKey:@"country_name"]);
}

希望,它会帮助你。

于 2013-04-17T06:48:32.427 回答
0
 NSMutableArray *wholeJsonArray = [LoginResult objectForKey:@"RootName"];
 NSMutableArray *loginArray = [[NSMutableArray alloc]init];

 for(int i = 0 ; i<[loginArray count];i++)
    {
        NSString *countryName=[[loginArray objectAtIndex:i]objectForKey:@"country_name"];
       [loginArray addObject:countryName];
    }

祝你好运 !!

于 2013-04-17T06:50:08.727 回答