本文介绍了iOS从URL字符串中删除特殊字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用NSURLRequest来调用此URL:

I want to call this URL using NSURLRequest:

http://www.test.com/query= {"tag1":üğişi ," tag2:"çöçödd}

http://www.test.com/query={"tag1":"üğişi","tag2":"çöçödd"}

这些字符分别是üğişi"和çöçödd" UTF8字符.我需要转换此URL以获得响应.你能帮我吗?

These characters which are "üğişi" and "çöçödd" UTF8 character. I need to convert this URL to get response. Can you help me?

推荐答案

使用NSString类的-(NSString*)stringByAddingPercentEscapesUsingEncoding:(NSStringEncoding)encoding;例程.像这样:

Use the -(NSString*)stringByAddingPercentEscapesUsingEncoding:(NSStringEncoding)encoding; routine of th NSString class. Like so:

NSString* url = @"http://www.test.com/query={\"tag1\":\"üğişi\",\"tag2\":\"çöçödd\"}";
NSString* urlEncoded = [url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

在这里您可以找到更多...

这篇关于iOS从URL字符串中删除特殊字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 11:09