2011-09-12 49 views
0

我使用這個例子解析: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解決了這個問題反序列化

+0

更改url與任何json字符串文件或webservice.It可能會幫助你 – aViNaSh

回答

0

你必須改變標籤。

rows = [dict objectForKey:@"news"]; 

編輯

NSURL *url = [NSURL URLWithString:@"http://...........jsontest.php"]; 
NSString *jsonreturn = [[NSString alloc] initWithContentsOfURL:url]; 
NSDictionary *results = [jsonreturn JSONValue]; 

試試這個工作對我來說。

+0

thanx的答覆,我已經改變了用戶的消息,但它不工作。 當我檢查字典變量時,它總是顯示空值。 這對我來說是個大問題。 NSData不轉換成NSDictionary NSDictionary變量顯示空值。 請幫忙。 –