开发者社区> 问答> 正文

关于解析JSON中的特殊字符

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

现在我已经获取的当地数据为Mexico,其中有一些特殊字符一起的下列错误:
`Unrecognized escape sequence. (13443):
`

使用下面的JSON编码:
`NSString *requestString = [jsonstring UTF8String];
`

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

展开
收起
爵霸 2016-03-19 09:29:43 2691 0
1 条回答
写回答
取消 提交回答
  • +(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发送给它。

    2019-07-17 19:07:14
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
神龙云服务器产品及技术深度解析 立即下载
弹性创造价值:基于ECS的最佳性价比实践解析 立即下载
又快又稳:阿里云下一代虚拟交换机解析 立即下载

相关镜像