我是 iphone 开发的菜鸟,我正在尝试从此链接解析 JSONArray 。问题是,当执行此代码时,它返回我的 NSArray 仅包含 4 个值,而不是链接处的 jSONArray 包含的 80 个值。我是否正确地将 NSDictionary 转换为 NSArray。任何帮助是极大的赞赏。我在这里学习本教程。
//parse out the json data
NSError* error;
NSDictionary* json = [NSJSONSerialization JSONObjectWithData:responseData //1
options:kNilOptions
error:&error];
NSArray* bitcoin = json; //2
NSLog(@"size of bitcoin is %lu", sizeof(bitcoin));
// 1) Get the bitcoin rate mtgoxUSD
for(int i = 0; i < sizeof(bitcoin); i++){
NSDictionary* forex = [bitcoin objectAtIndex:i];
NSString *mtgoxUSD = [forex objectForKey:@"symbol"];
NSLog(@"value against mtgoxUSD %@", mtgoxUSD);
if (mtgoxUSD==@"mtgoxUSD") {
NSString *bitcoinrate = [forex objectForKey:@"avg"];
if (bitcoinrate==@""||bitcoinrate==NULL) {
currencyBTC=1;
NSLog(@"currencyBTC: is 1");
}else{
currencyBTC=[bitcoinrate floatValue];
NSLog(@"currencyBTC: %f", currencyBTC);
}
break;
}
}