Wong Gut
Wong Gut

Reputation: 71

How To Convert JSON String That Contains Encoded Unicode

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?

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

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

Any help is much appreciated.

Upvotes: 6

Views: 17219

Answers (2)

Codo
Codo

Reputation: 79033

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.

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.

A correct JSON snippet would be:

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

Giving:

  • records:
    • []
      • description: 蒜肉
      • id: 282

Upvotes: 7

Baz1nga
Baz1nga

Reputation: 15579

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);  

Upvotes: -1

Related Questions