-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
 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 に答える
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 に答える