问题:我无法正确解析JSON文件中的数据到NSArray。 UTF编码不能按预期工作。Json到iOS编码错误
我的JSON看起来像:
[
{"Name":"Marcos","Address":"1234 Brasil Av. São Paulo - SP","Latitude":"-23.000","Longitude":"-46.70"},{"Name":"Mario","Address":"1000 Washignton Luiz Av. Itú SP","Latitude":"-20.0000","Longitude":"-46.000"}
]
我的Objective-C代码为:
NSError *error = nil;
NSURL *jsonUrl = [[NSURL alloc]initWithString:
@"http://marcosdegni.com.br/teste/webservice_teste.php"];
NSString *jsonString = [NSString stringWithContentsOfURL:jsonUrl
encoding:NSUTF8StringEncoding error:&error];
NSLog(@"jsonString: %@ , Error:%@:" ,jsonString, error); //(1)
if (!error) {
NSError *error2 = nil;
NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
NSArray * jsonArray = [NSJSONSerialization JSONObjectWithData:jsonData options:kNilOptions error:&error2];
NSLog(@"\n\nArray: %@" \nError:[email protected], jsonArray, error2); //(2)
//(*1*) This log show the content's as they are expected: note the characters ã and ú on the address fields.
//(*2*) The logs from the array and the dictionary show this charters as it's UNIX codes:\U00e and \U00fa respectively.
你为什么要解码相同的数据两次,一次是数组,一次是字典?什么不工作? “错误”(你错误地提供了'nil')报告(纠正了那个错误之后)是什么? – 2014-11-06 01:57:13
这是我两次尝试获取我的数据。两人都没有工作。为了清晰起见,我排除了这个dic。无 - >错误取而代之。 Tks – 2014-11-06 02:04:50
换句话说,没有什么不对。扩展的UNICODE数据按照预期显示在NSLog中。 – 2014-11-06 02:05:31