DataContractJsonSerializer dataSerializer = new DataContractJsonSerializer(request.getBizContentClass()); MemoryStream msObj = new MemoryStream(); dataSerializer.WriteObject(msObj, request.getBizContent()); msObj.Position = 0; StreamReader sr = new StreamReader(msObj, Encoding.GetEncoding(charset)); String json = sr.ReadToEnd(); sr.Close(); msObj.Close(); //JavaScriptSerializer serializer = new JavaScriptSerializer(); //String json = serializer.Serialize(request.BizContent);
反序列化
MemoryStream ms1 = new MemoryStream(Encoding.GetEncoding(charset).GetBytes(respBizContentStr)); using (MemoryStream ms = new MemoryStream(Encoding.GetEncoding(charset).GetBytes(respBizContentStr))) { DataContractJsonSerializer deseralizer = new DataContractJsonSerializer(request.getResponseClass()); response = (IcbcResponse)deseralizer.ReadObject(ms) as IcbcResponse; }