我使用這個例子解析:http://tempered.mobi/sites/default/files/JSonArticle.zip數據使用JSON觸摸
但它表明在時間解析空值。
我的PHP代碼輸出:
{"news":[{"title":"DurianFM Android Application"},{"title":"Hari Raya"},{"title":"C"}]}
iPhone代碼:
(void)viewDidLoad {
[super viewDidLoad];
NSURL *url = [NSURL URLWithString:@"http://...........jsontest.php"];
NSString *jsonreturn = [[NSString alloc] initWithContentsOfURL:url];
NSLog(jsonreturn); // Look at the console and you can see what the restults are
NSData *jsonData = [jsonreturn dataUsingEncoding:NSUTF32BigEndianStringEncoding];
NSError *error = nil;
// In "real" code you should surround this with try and catch
NSDictionary * dict = [[[CJSONDeserializer deserializer] deserializeAsDictionary:jsonData error:&error] retain];
if (dict)
{
rows = [dict objectForKey:@"news"];
}
NSLog(@"Array: %@",rows);
[jsonreturn release];
}
當我檢查字典變量它總是顯示爲空值。 這對我來說是個大問題。 NSData不轉換成NSDictionary NSDictionary變量顯示空值。
請大家幫忙。
我已經改變deserializeAsDictionary解決了這個問題反序列化
更改url與任何json字符串文件或webservice.It可能會幫助你 – aViNaSh