【发布时间】:2013-12-05 22:51:20
【问题描述】:
我正在尝试序列化一个在他的字符串中具有特殊字符的对象(如 ø 或 æ)。
问题是当我使用这样的特殊字符时,我的 JSON 的最后一位被截断了?
没有特殊字符:
{"availability":"busy","name":"test","visibility":"public"}
带有特殊字符:
{"availability":"busy","name":"tøst","visibility":"public"
我注意到对于每个特殊字符,我的 JSON 字符串中都会截断一个字符。
我使用以下代码进行序列化:
// create new appointment
AppointmentClass appoint = new AppointmentClass();
appoint.name = subjectstring;
appoint.availability = "busy";
appoint.visibility = "public";
// generate json string from Appointment class
MemoryStream stream = new MemoryStream();
DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(AppointmentClass));
ser.WriteObject(stream, appoint);
stream.Position = 0;
StreamReader sr = new StreamReader(stream);
string payload = sr.ReadToEnd();
【问题讨论】:
标签: c# json windows-phone character