2012-01-09 5 views
3

私はJSON-「Abrabic Language」のテキストを含むJSONを解析する方法は?

NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding]; 

NSData *JsonData = [responseString dataUsingEncoding:NSISOLatin1StringEncoding]; 

NSString* newStr = [[NSString alloc] initWithData:JsonData encoding:NSUTF8StringEncoding]; 

NSLog(@"New str - %@",newStr); 

NSDictionary *response = [[NSString stringWithUTF8String:[JsonData bytes]] JSONValue]; 

NSLog(@"%@",response); 

を解析するために、次のコードを使用していますが、この応答は、「NULL値」を与えています。

答えて

1

すべての最初は、あなたのJSONファイルでこれを追加 - (つまり、PHPファイルの場合)(私はエラーがあるかもしれないと思う...)

<? 
header('Content-Type: text/javascript; charset=utf-8'); 

?> 

そして、このようにJSONを使う -

NSString* newStr = [[NSString alloc] initWithContentsOfURL:[NSURL URLWithString:@"yout link to json file"] encoding:NSUTF8StringEncoding error:nil]; 

NSLog(@"new str - %@",newStr); 



NSDictionary *response = [newStr JSONValue]; 

NSLog(@"json dictionary - %@",response); 


NSLog(@"author - %@",[[[response objectForKey:@"response"] objectForKey:@"SportsNewList"] objectForKey:@"author"]); 

問題が発生した場合のコメント投稿

関連する問題