O_1001_O 于 2013.07.04 16:26 提问
- 解析JSON中的特殊字符
-
从 foursquare api抓取本地数据,然后将数据传递到
webservice
添加给database
。现在我已经获取的当地数据为Mexico,其中有一些特殊字符一起的下列错误:
Unrecognized escape sequence. (13443):
使用下面的JSON编码:
NSString *requestString = [jsonstring UTF8String];
如何解析这些特殊字符?(比如西班牙 Éspanol)
-
- Chengzi_963 2013.07.04 16:42
- 已采纳
+(NSString *)http_post_method_changed:(NSString *)url content:(NSString *)jsonContent
{
NSURL *theURL = [NSURL URLWithString:url];
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:theURL cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:20.0f];
NSData *requestData = [jsonContent dataUsingEncoding:NSUTF8StringEncoding];
[theRequest setHTTPMethod:@"POST"];
[theRequest setValue:@"application/json" forHTTPHeaderField:@"Accept"];
[theRequest setValue:@"application/json; charset=UTF-8" forHTTPHeaderField:@"Content-Type"];
[theRequest setValue:[NSString stringWithFormat:@"%d", [requestData length]] forHTTPHeaderField:@"Content-Length"];
[theRequest setHTTPBody: requestData];
NSURLResponse *theResponse = NULL;
NSError *theError = NULL;
NSData *theResponseData = [NSURLConnection sendSynchronousRequest:theRequest returningResponse:&theResponse error:&theError];
NSString *data=[[NSString alloc]initWithData:theResponseData encoding:NSUTF8StringEncoding];
NSLog(@"url to send request= %@",url);
NSLog(@"response1111:-%@",data);
return data;
}
用上面的代码就可以转换特殊字符了。
将你的url和json发送给它。
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!