Objective-C 中的西里尔文 NSString 到 Unicode
我想通过 Web 服务将西里尔字符串作为参数从 iPhone 发送到 .net 框架服务器。我应该如何正确编码?我希望结果是这样的:
“myParam=\U0438\U0422”
如果可行,是西里尔字母还是拉丁字母有关系吗?
我应该如何在使用 C# 的服务器上对其进行解码?
I want to send Cyrillic string as parameter over webservice from iPhone to .net framework server. How should I encode it correctly? I would like the result to be something like:
"myParam=\U0438\U0422"
If it's doable, would it matter if it is Cyrillic or just Latin letters?
And how should I decode it on the server, where I am using C#?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
真的吗?这不是 URL 参数编码的标准,它是:
假设使用 UTF-8 编码,这将是 ASP.NET 应用程序的默认编码。然后,您不需要手动解码任何内容,Request.QueryString/Form 集合将为您提供本机 Unicode 字符串。
URL 编码通常使用
stringByAddingPercentEscapesUsingEncoding
来完成,只是它有点损坏。请参阅此问题了解背景信息。Really? That's not the standard for URL parameter encoding, which would be:
assuming the UTF-8 encoding, which will be the default for an ASP.NET app. You don't need to manually decode anything then, the Request.QueryString/Form collections will give you native Unicode strings.
URL-encoding would normally be done using
stringByAddingPercentEscapesUsingEncoding
, except that it's a bit broken. See this question for background.C# 字符串默认编码 Unicode。所以对你来说,确保你的字符串像 unicode 一样编码就足够了。
一旦它像unicode一样编码,如果你在那里输入西里尔文、拉丁文、阿拉伯文或任何字母,就没有任何区别,应该足以使用正确的代码页。
编辑
正在寻找..好文章全球化逐步
修正@chibacity 注意:即使 C# 中的默认字符串编码是 Unicode,您的情况下的 Web 服务也使用 UTF-8。 (比较灵活的一种)
The C# strings default encoding Unicode. So for you, it's enough to ensure that your string is encoded like unicode.
One time it's encoded like unicode, there is no any difference if you put there cyrilic, latin, arabic or whatever letters, should be enough to use correct Code Page.
EDIT
Was searching for.. good article here Globalization Step by Step
Correction by @chibacity note: even if default string encoding is Unicode in C#, Web Services in your case use UTF-8. (more flexible one)