我想用SBJson解析一些json數據來顯示當前溫度。本教程中的示例代碼完美:Tutorial: Fetch and parse JSONSBJson顯示爲null
當我將代碼更改爲我的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代碼。
如果這是一個新項目,您應該考慮使用Apple的官方['NSJSONSerialization'](https:// developer。apple.com/library/ios/#documentation/Foundation/Reference/NSJSONSerialization_Class/Reference/Reference.html)。 – rid
瞭解如何閱讀JSON - 大概需要5分鐘:http://www.json.org/ –
與您的問題矛盾* SBJson不顯示任何*。它只是用於解析JSon。 – viral