O_1001_O
2013-07-04 08:26
采纳率: 80%
浏览 7.3k
已采纳

解析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发送给它。

    打赏 评论

相关推荐 更多相似问题