如何在C#中为特殊字符编码和解码JSON字符串 [英] How to encode and decode JSON String for special charecter in C#

查看:124
本文介绍了如何在C#中为特殊字符编码和解码JSON字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的所有人,
我使用 JSON.NET v4.0.30319来处理json
我在使用特殊字符时遇到问题,
我正在寻找在c#中建立两个函数,第一个处理我的json主体处理特殊字符",第二个返回真实的json文本

关于他的功能m的任何想法都可以帮助我进行构建.

问候

Dear All,
i use JSON.NET v4.0.30319 to working with json
i have problems with special charecter,
am looking for build two functions in c# first one process my json body "process special charecters" and second return back the real json text

any idea about his function m can you help me for build it.

Regards

推荐答案

没有这样的问题:

There is no such problem:

任何字符都可以转义.如果字符在基本多语言平面中(U + 0000至U + FFFF),则可以表示为六个字符的序列:反向固线,后跟小写字母u,后跟四个编码该字符的十六进制数字字符的代码点.十六进制字母A至F可以为大写或小写.因此,例如,仅包含单个反斜线字符的字符串可以表示为"\ u005C".

Any character may be escaped. If the character is in the Basic Multilingual Plane (U+0000 through U+FFFF), then it may be represented as a six-character sequence: a reverse solidus, followed by the lowercase letter u, followed by four hexadecimal digits that encode the character''s code point. The hexadecimal letters A though F can be upper or lowercase. So, for example, a string containing only a single reverse solidus character may be represented as "\u005C".



请参阅:
http://en.wikipedia.org/wiki/JSON [ http://www.ecma-international.org/publications/standards/Ecma-262.htm [ ^ ],
http://tools.ietf.org/html/rfc4627 [ http://msdn.microsoft.com/en-us/library/ms733127.aspx [ ^ ],
http://msdn.microsoft.com/en-us/library/system.runtime.serialization.json.datacontractjsonserializer.aspx [ ^ ].

请查看我过去对类似或相关问题的回答:
如何在我的表单应用程序? [ ^ ],
创建属性文件... [反序列化json字符串数组 [



Please see:
http://en.wikipedia.org/wiki/JSON[^],
http://www.ecma-international.org/publications/standards/Ecma-262.htm[^],
http://tools.ietf.org/html/rfc4627[^].

And of course, use DataContract and System.Runtime.Serialization.Json.DataContractJsonSerializer:
Please see:
http://msdn.microsoft.com/en-us/library/ms733127.aspx[^],
http://msdn.microsoft.com/en-us/library/system.runtime.serialization.json.datacontractjsonserializer.aspx[^].

Please see my past answers to similar or related questions:
How can I utilize XML File streamwriter and reader in my form application?[^],
Creating property files...[^],
deseralize a json string array[^].

—SA


您应该可以只使用
You should be able to just use a DataContractJsonSerializer[^].

/ravi


这篇关于如何在C#中为特殊字符编码和解码JSON字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆