現在の温度を表示するために、SBJson でいくつかの json データを解析しようとしています。このチュートリアルのサンプル コードは完璧に機能します:チュートリアル: JSON のフェッチと解析
コードを json フィードに変更すると、null が返されます。私は JSON の初心者ですが、見つけたすべてのチュートリアルとドキュメントに従いました。使用した json ソース: JSON ソース
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 コードは既に実装しています。