如何转换包含编码Unicode的JSON字符串

时间:2021-03-23 20:13:27

Could anyone tell me how to convert the following json object string, which contains encoded unicode characters (Chinese in this case) to human readable one using c# in asp.net?

任何人都可以告诉我如何将以下json对象字符串转换为人类可读的字符串,其中包含编码的u​​nicode字符(在本例中为中文),在asp.net中使用c#?

records:[{"description":"\u849c\u8089","id":282}]

The string is submitted via Ajax from an Ext JS web application.

该字符串是通过Ajax从Ext JS Web应用程序提交的。

Any help is much appreciated.

任何帮助深表感谢。

2 个解决方案

#1


5  

There is no need to convert this string in any special manner. Any JSON decoder that more or less sticks to the specification will automatically create a correct string for the description attribute.

无需以任何特殊方式转换此字符串。任何或多或少坚持规范的JSON解码器都会自动为描述属性创建正确的字符串。

Update:

更新:

However, your current sample is not valid JSON. It's missing brackets or braces around the complete sample and it's missing double qutoes around records.

但是,您当前的示例无效JSON。它缺少整个样本周围的括号或括号,并且在记录周围缺少双qutoes。

A correct JSON snippet would be:

一个正确的JSON片段是:

{"records":[{"description":"\u849c\u8089","id":282}]}

Giving:

赠送:

  • records:
    • []
      • description: 蒜肉
      • 描述:蒜肉
      • id: 282
      • id:282
    • []描述:蒜肉id:282
  • 记录:[]描述:蒜肉id:282

#2


0  

I am guessing it should be done as follows:

我猜它应该按如下方式完成:

var  bytes  =  Encoding.Unicode.GetBytes("<unicode string>"); 
//  Return  the  Base64-encoded  string.  
string  str  =    Convert.ToBase64String(b);  

#1


5  

There is no need to convert this string in any special manner. Any JSON decoder that more or less sticks to the specification will automatically create a correct string for the description attribute.

无需以任何特殊方式转换此字符串。任何或多或少坚持规范的JSON解码器都会自动为描述属性创建正确的字符串。

Update:

更新:

However, your current sample is not valid JSON. It's missing brackets or braces around the complete sample and it's missing double qutoes around records.

但是,您当前的示例无效JSON。它缺少整个样本周围的括号或括号,并且在记录周围缺少双qutoes。

A correct JSON snippet would be:

一个正确的JSON片段是:

{"records":[{"description":"\u849c\u8089","id":282}]}

Giving:

赠送:

  • records:
    • []
      • description: 蒜肉
      • 描述:蒜肉
      • id: 282
      • id:282
    • []描述:蒜肉id:282
  • 记录:[]描述:蒜肉id:282

#2


0  

I am guessing it should be done as follows:

我猜它应该按如下方式完成:

var  bytes  =  Encoding.Unicode.GetBytes("<unicode string>"); 
//  Return  the  Base64-encoded  string.  
string  str  =    Convert.ToBase64String(b);