2011-09-12 4 views
0

와 구문 분석 : http://tempered.mobi/sites/default/files/JSonArticle.zip데이터는 내가이 예제를 사용하고 JSON 터치

그러나 시간 구문 분석에서 null 값을 보여줍니다.

내 PHP 코드 출력 :

{"news":[{"title":"DurianFM Android Application"},{"title":"Hari Raya"},{"title":"C"}]} 

아이폰 코드 : 나는 DICT 변수을 확인할 때

(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]; 
} 

는 항상 null 값을 보여줍니다. 큰 문제입니다. NSData는 NSDictionary로 변환되지 않습니다. NSDictionary 변수는 null 값을 표시합니다.

도와주세요.

난 당신이 태그를 변경해야

+0

json 문자열 파일 또는 webservice 중 하나를 사용하여 url을 변경하십시오. – aViNaSh

답변

0

역 직렬화하는 변경 deserializeAsDictionary이 문제를 해결했다.

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

편집

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

것은 나를 위해 작동이 하나를 시도하십시오.

+0

고맙습니다. 회신을 위해 유용 할 수 있지만 사용자를 뉴스로 변경했지만 작동하지 않습니다. dict 변수를 검사 할 때 항상 null 값을 표시합니다. 큰 문제입니다. NSData가 NSDictionary로 변환되지 않습니다. NSDictionary 변수에 null 값이 표시됩니다. 도와주세요. –

관련 문제