zoukankan      html  css  js  c++  java
  • C#JSON格式数据的转换

    json格式字符串转化为json对象:
    JObject calculate = (JObject)JsonConvert.DeserializeObject(Rep.Request["data"].ToString());
    或者
    JArray calculate = (JArray)JsonConvert.DeserializeObject(Rep.Request["data"].ToString());

    JSON对象转化为json字符串:
    string strResult = JsonConvert.SerializeObject(dtResult);

    JArray是数组数据[{},{},{}],里面可以有多个JObject
    JObject是json数据{}

    取出里面的key和value用JToken
    JObject json = //获得一个JObject对象
    /*
    {
    "records": [
    {
    "ID": "ABC",
    "OperationPatchID": "1",
    "s05055396": "120.93900",
    "s05055099": "14.44790",
    "s04026131": "Open lot",
    "s04020195": "3334",
    "s03006029": "2014/7/23 0:00:00",
    "s03006045": "BAC"
    }
    ],
    "count": 1
    } Newtonsoft.Json.Linq.JObject
    */

    StringBuilder sb = new StringBuilder("<div>");
    JToken record = json["records"][0];
    foreach(JProperty jp in record)
    {
    sb.Append(String.Format(@"<span>{0}</span>:<span>{1}</span>"
    ,jp.Name
    ,jp.Value));
    }

  • 相关阅读:
    单例模式
    collections额外数据类型
    logging的简单使用
    杂记
    字符编码
    面向对象编程简介
    logging模块
    re与subprocess模块
    oepnpyxl模块 与excle交互
    json序列化模块
  • 原文地址:https://www.cnblogs.com/zhongzunmu/p/5430024.html
Copyright © 2011-2022 走看看