從 foursquare api抓取本地數據,然後將數據傳遞到webservice
添加給database
。
現在我已經獲取的當地數據為Mexico,其中有一些特殊字符一起的下列錯誤:
Unrecognized escape sequence. (13443):
使用下面的JSON編碼:
NSString *requestString = [jsonstring UTF8String];
如何解析這些特殊字符?(比如西班牙 Éspanol)
+(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發送給它。