自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

探索非同凡響的Json數(shù)據(jù)格式說明

開發(fā)
這樣,在Response.Write(value.ToString())就會顯示paulleder,成功獲得json的值了。這里主要用到Json數(shù)據(jù)格式。

Json數(shù)據(jù)格式在日常工作中還是非常實用的,只需要Json數(shù)據(jù)就可以了,如果對Json數(shù)據(jù)不太了解,那就必須先要對下面就對  進行學習,下面就對Json數(shù)據(jù)格式的代碼進行系統(tǒng)的分析與研究。。#t#

看到另一篇C#解析Json的類 的文章現(xiàn)在json因為輕型,越來越流行,部門內部的數(shù)據(jù)標準趨向于json,所以開始學習。本次工作內容是要將以下數(shù)據(jù)解析成.Net可以使用的數(shù)據(jù),返回的數(shù)據(jù)除了header,其他的都是可變的,也就是說結構不是固定的。完全由用戶選擇,所以選擇了生成DataTable。

Json數(shù)據(jù)格式如下:

  1. using System;  
  2.  
  3. using System.Collections.Generic;  
  4.  
  5. using System.Text;  
  6.  
  7. using System.Data;  
  8.  
  9. using System.Web.Script.Serialization;  
  10.  
  11.  
  12.  
  13. namespace Tencent.Itil.Cmsi.Common  
  14.  
  15. {  
  16.  
  17.      public class GeneralSearchResult  
  18.  
  19.      {  
  20.  
  21.          public Header header = new Header();  
  22.  
  23.          private DataTable fieldDefine = new DataTable();  
  24.  
  25.          /// <summary> 
  26.  
  27.          /// 返回的數(shù)據(jù)結構定義,無數(shù)據(jù)  
  28.  
  29.          /// </summary> 
  30.  
  31.          public DataTable FieldDefine  
  32.  
  33.          {  
  34.  
  35.              get { return fieldDefine; }  
  36.  
  37.              set { fieldDefine = value; }  
  38.  
  39.          }  
  40.  
  41.  
  42.  
  43.          private DataTable retrunData = new DataTable();  
  44.  
  45.          /// <summary> 
  46.  
  47.          /// 返回的數(shù)據(jù),格式為DataTable,結構和FieldDefine中的結構一樣  
  48.  
  49.          /// </summary> 
  50.  
  51.          public DataTable RetrunData  
  52.  
  53.          {  
  54.  
  55.              get { return retrunData; }  
  56.  
  57.              set { retrunData = value; }  
  58.  
  59.          }  
  60.  
  61.  
  62.  
  63.          /// <summary> 
  64.  
  65.          /// 將json數(shù)據(jù)轉換為定義好的對象,數(shù)據(jù)轉換為DataTable  
  66.  
  67.          /// </summary> 
  68.  
  69.          /// <param name="jsonText"></param> 
  70.  
  71.          /// <returns></returns> 
  72.  
  73.          public static GeneralSearchResult GetTransformData(string jsonText)  
  74.  
  75.          {  
  76.  
  77.              GeneralSearchResult gsr = new GeneralSearchResult();  
  78.  
  79.  
  80.  
  81.              JavaScriptSerializer s = new JavaScriptSerializer();  
  82.  
  83.              Dictionary<string, object> JsonData = (Dictionary<string, object>)s.DeserializeObject(jsonText);  
  84.  
  85.              Dictionary<string, object> dataSet = (Dictionary<string, object>)JsonData["dataSet"];  
  86.  
  87.              Dictionary<string, object> header = (Dictionary<string, object>)dataSet["header"];  
  88.  
  89.              Dictionary<string, object> fieldDefine = (Dictionary<string, object>)dataSet["header"];  
  90.  
  91.              Dictionary<string, object> data = (Dictionary<string, object>)dataSet["data"];  
  92.  
  93.              object[] rows = (object[])data["row"];  
  94.  
  95.              gsr.header.Version = header["version"].ToString();  
  96.  
  97.              gsr.header.ErrorInfo = header["errorInfo"].ToString();  
  98.  
  99.              gsr.header.ReturnCode = header["returnCode"].ToString();  
  100.  
  101.              gsr.header.ReturnRows = Convert.ToInt16(header["returnRows"]);  
  102.  
  103.              gsr.header.TotalRows = Convert.ToInt16(header["totalRows"]);  
  104.  
  105.  
  106.  
  107.              Dictionary<string, object> dicFieldDefine = (Dictionary<string, object>)dataSet["fieldDefine"];  
  108.  
  109.              foreach (KeyValuePair<string, object> ss in dicFieldDefine)  
  110.  
  111.              {  
  112.  
  113.  
  114.  
  115.                  gsr.FieldDefine.Columns.Add(ss.Key, typeof(string));  
  116.  
  117.  
  118.  
  119.              }  
  120.  
  121.              gsrgsr.RetrunData = gsr.FieldDefine.Clone();  
  122.  
  123.              foreach (object ob in rows)  
  124.  
  125.              {  
  126.  
  127.                  Dictionary<string, object> val = (Dictionary<string, object>)ob;  
  128.  
  129.                  DataRow dr = gsr.RetrunData.NewRow();  
  130.  
  131.                  foreach (KeyValuePair<string, object> sss in val)  
  132.  
  133.                  {  
  134.  
  135.                      dr[sss.Key] = sss.Value;  
  136.  
  137.                  }  
  138.  
  139.                  gsr.RetrunData.Rows.Add(dr);  
  140.  
  141.              }  
  142.  
  143.              return gsr;  
  144.  
  145.          }  
  146.  
  147.          /// <summary> 
  148.  
  149.          /// 數(shù)據(jù)文件頭定義  
  150.  
  151.          /// </summary> 
  152.  
  153.          public class Header  
  154.  
  155.          {  
  156.  
  157.              private string version;  
  158.  
  159.              /// <summary> 
  160.  
  161.              /// 版本  
  162.  
  163.              /// </summary> 
  164.  
  165.              public string Version  
  166.  
  167.              {  
  168.  
  169.                  get { return version; }  
  170.  
  171.                  set { version = value; }  
  172.  
  173.              }  
  174.  
  175.              private string returnCode;  
  176.  
  177.              /// <summary> 
  178.  
  179.              /// 結果碼,0為正常,否則為有錯誤  
  180.  
  181.              /// </summary> 
  182.  
  183.              public string ReturnCode  
  184.  
  185.              {  
  186.  
  187.                  get { return returnCode; }  
  188.  
  189.                  set { returnCode = value; }  
  190.  
  191.              }  
  192.  
  193.              private string errorInfo;  
  194.  
  195.              /// <summary> 
  196.  
  197.              /// 如果ReturnCode為非0時的錯誤信息  
  198.  
  199.              /// </summary> 
  200.  
  201.              public string ErrorInfo  
  202.  
  203.              {  
  204.  
  205.                  get { return errorInfo; }  
  206.  
  207.                  set { errorInfo = value; }  
  208.  
  209.              }  
  210.  
  211.              private int totalRows;  
  212.  
  213.              /// <summary> 
  214.  
  215.              /// 查詢結果總行數(shù)  
  216.  
  217.              /// </summary> 
  218.  
  219.              public int TotalRows  
  220.  
  221.              {  
  222.  
  223.                  get { return totalRows; }  
  224.  
  225.                  set { totalRows = value; }  
  226.  
  227.              }  
  228.  
  229.              private int returnRows;  
  230.  
  231.              /// <summary> 
  232.  
  233.              /// 返回的數(shù)據(jù)行數(shù)  
  234.  
  235.              /// </summary> 
  236.  
  237.              public int ReturnRows  
  238.  
  239.              {  
  240.  
  241.                  get { return returnRows; }  
  242.  
  243.                  set { returnRows = value; }  
  244.  
  245.              }  
  246.  
  247.          }  
  248.  
  249.      }  
  250.  
責任編輯:chenqingxiang 來源: 互聯(lián)網(wǎng)
相關推薦

2014-08-12 10:15:42

數(shù)據(jù)格式JSONXML

2009-09-07 19:02:07

JSON是什么

2013-03-27 10:51:44

iOSjson解析網(wǎng)絡交互數(shù)據(jù)格式解析

2011-04-11 09:48:59

AjaxWEB服務

2024-04-15 13:13:04

PythonJSON

2010-01-06 13:23:20

JSON數(shù)據(jù)格式

2018-09-25 15:28:57

維諦技術

2024-11-12 12:08:06

JSON數(shù)據(jù)技巧

2010-01-06 15:03:34

JSON格式封裝

2011-12-02 10:34:54

Win7

2010-01-07 17:48:02

JSON結構

2010-01-06 17:06:05

Json格式

2010-01-05 17:35:09

JSON數(shù)組格式

2021-11-11 23:16:33

前端數(shù)據(jù)格式Web

2010-01-08 15:37:59

JSON數(shù)據(jù)

2024-12-19 00:12:02

APIJSON數(shù)據(jù)

2011-04-11 13:14:58

AjaxWEB服務

2010-07-09 10:42:38

HART協(xié)議

2010-07-09 10:27:33

SQL Server數(shù)

2022-06-05 14:57:35

發(fā)送釘釘運維架構
點贊
收藏

51CTO技術棧公眾號