我正在尝试使用 SBJson 解析一些 json 数据以显示当前温度。本教程中的示例代码完美运行:教程:获取和解析 JSON
当我将代码更改为我的 json 提要时,我得到一个空值。我对 JSON 有点陌生,但遵循了我找到的每个教程和文档。我使用的json源:JSON Source
我的 sbjson 代码:
NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
self.responseData = nil;
NSArray* currentw = [(NSDictionary*)[responseString JSONValue] objectForKey:@"current_weather"];
//choose a random loan
NSDictionary* weathernow = [currentw objectAtIndex:0];
//fetch the data
NSNumber* tempc = [weathernow objectForKey:@"temp_C"];
NSNumber* weatherCode = [weathernow objectForKey:@"weatherCode"];
NSLog(@"%@ %@", tempc, weatherCode);
当然,我已经实现了其他 sbjson 代码。