O_1001_O 2013-07-04 08:26 采纳率: 0%
浏览 7360
已采纳

解析JSON中的特殊字符

从 foursquare api抓取本地数据,然后将数据传递到webservice 添加给database

现在我已经获取的当地数据为Mexico,其中有一些特殊字符一起的下列错误:

Unrecognized escape sequence. (13443):

使用下面的JSON编码:

NSString *requestString =  [jsonstring UTF8String];

如何解析这些特殊字符?(比如西班牙 Éspanol)

  • 写回答

1条回答

  • Chengzi_963 2013-07-04 08: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发送给它。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 MATLAB动图问题
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题