zoukankan      html  css  js  c++  java
  • C# DataContractJsonSerializer

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

     反序列化

                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;
                }
    View Code
  • 相关阅读:
    链式栈的C++实现
    Java面试之设计模式二
    前端资源
    Java面试之异常
    Java面试之序列化
    Java面试之重写(Override)与重载(Overload)
    项目视图展示
    Java面试之集合
    Java面试之SSH框架面试题集锦
    JDBC技术
  • 原文地址:https://www.cnblogs.com/hofmann/p/11640427.html
Copyright © 2011-2022 走看看