SBJson과 함께 일부 json 데이터를 분석하여 현재 온도를 표시하려고합니다. 이 자습서의 예제 코드는 완벽하게 작동합니다. Tutorial: Fetch and parse JSONSBJson이 null을 표시합니다.
코드를 json 피드로 변경하면 null이됩니다. 나는 JSON에 처음 익숙하지만, 내가 찾은 모든 튜토리얼과 문서를 따랐다. 내가 사용하는 JSON 소스 : sbjson와 JSON Source
내 코드 :
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 코드를 구현 한
.
새로운 프로젝트 인 경우 Apple의 공식 ['NSJSONSerialization'] (https : // developers.apple.com/library/ios/#documentation/Foundation/Reference/NSJSONSerialization_Class/Reference/Reference.html). – rid
JSON을 읽는 방법 알아보기 - 5 분 정도 걸립니다. http://www.json.org/ –
질문과 모순 됨 * SBJson은 아무 것도 표시하지 않습니다 *. JSon을 파싱하기위한 것입니다. – viral