我有应用程序在facebook API中读取地方的json 我试着去韩国读书 json中的字符串是:
“name”:“\ uc9c0 \ uc9c0 \ ud5a5”,
我的结果是:
Item [“name”]。ToString()= [] [] [] []
我该怎么编码呢?
我试过了:
Encoding korenEncoding = Encoding.GetEncoding(50225);
byte[] convertedToUtf8 = Encoding.Convert(korenEncoding,Encoding.UTF8,korenEncoding.GetBytes(Item["name"].ToString()));
string name = Encoding.UTF8.GetString(convertedToUtf8);
它不起作用, 感谢
答案 0 :(得分:4)
你用什么来反序列化json?我尝试使用System.Runtime.Serialization.Json
并正确解码。还要确保数据库列支持unicode数据
[DataContract]
class thinger
{
[DataMember]
public string name;
}
string snip = @"{""name"": ""\uc9c0\uc9c0\ud5a5""}";
Byte[] bytes = Encoding.Unicode.GetBytes(snip);
MemoryStream jsonstream = new MemoryStream(bytes);
jsonstream.Write(bytes, 0, bytes.Length);
jsonstream.Seek(0, SeekOrigin.Begin);
DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(thinger));
thinger output = (thinger)ser.ReadObject(jsonstream);
//output.name = 지지향