zoukankan      html  css  js  c++  java
  • JsonConvert序列化

    1 //data 是个二进制的数据流,序列化成对于的实体类型,实体类型就被赋值了。
    var so = (Models.VWMSSO)JsonConvert.DeserializeObject(Encoding.UTF8.GetString(data), typeof(Models.VWMSSO));
    2 如同3中的obj
    将封装的JSon可以序列划成对于的xmldocument的类型
    XmlDocument doc = JsonConvert.DeserializeXmlNode(JsonConvert.SerializeObject(obj));
    3   序列化内容进行请求
    var Obj = new JObject { {"head", new JObject { { "transCode", "A1001" }, { "transId", transid } } }, {"body", new JObject { } } }; //每次都请求下新的token
    //StringContent 的命名空间是System.Net.Http,是可以用于呼叫接口时用于携带内容
    HttpContent contenttoken = new StringContent(JsonConvert.SerializeObject(Obj), Encoding.UTF8, "application/json"); var messagetoken = await _httpClientFactory.CreateClient().PostAsync(tokenUrl, contenttoken);
    JsonConvert.SerializeObject  这个是序列化成string 类型。就是json的文本类型
    JsonConvert.Deserializexxx   反序列化,就是把json序列化成自己需要的其他非json的类型,Eg:1和2
     JObject o = new JObject(
                      new JProperty("v", "1.0"),
                      new JProperty("timestamp", (new DateTimeOffset(DN.DeliveryDateTime).ToUnixTimeMilliseconds()).ToString()),
                      new JProperty("method", "delivery"),
                      new JProperty("format", "json"),
                      new JProperty("flag", account),
                      new JProperty("order", OrderSn),
                      new JProperty("Number", Number),
                      new JProperty("logistics", ExpressCode),
                      new JProperty("mfrom", "总店()"));
    
                    string s = Newtonsoft.Json.JsonConvert.SerializeObject(o);
    //下面这个就是将s 反序列成Dictionary<string,string>的字典的类型。 Dictionary
    <string, string> values = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<string, string>>(s); string ss = GetSignature(values, secret); o.Add(new JProperty("sign", ss));
     Json = JsonConvert.SerializeObject(reqdata)//这个是将实体对象序列化成Json
  • 相关阅读:
    L2-004. 这是二叉搜索树吗?
    CF934A A Compatible Pair
    CF937B Vile Grasshoppers
    CF940B Our Tanya is Crying Out Loud
    ZOJ 3182 Nine Interlinks
    ZOJ 3175 Number of Containers
    Codeforces Round #193 (Div. 2) B
    CodeForces 149D Coloring Brackets
    POJ 2653 Pick-up sticks(计算几何)
    UVA 12506 Shortest Names
  • 原文地址:https://www.cnblogs.com/ZkbFighting/p/12778040.html
Copyright © 2011-2022 走看看