日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第6页亚洲成人精品一区|亚洲黄色天堂一区二区成人|超碰91偷拍第一页|日韩av夜夜嗨中文字幕|久久蜜综合视频官网|精美人妻一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
探索非同凡響的Json數(shù)據(jù)格式說明

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

為澄邁等地區(qū)用戶提供了全套網(wǎng)頁設(shè)計制作服務(wù),及澄邁網(wǎng)站建設(shè)行業(yè)解決方案。主營業(yè)務(wù)為成都網(wǎng)站制作、成都網(wǎng)站建設(shè)、外貿(mào)營銷網(wǎng)站建設(shè)、澄邁網(wǎng)站設(shè)計,以傳統(tǒng)方式定制建設(shè)網(wǎng)站,并提供域名空間備案等一條龍服務(wù),秉承以專業(yè)、用心的態(tài)度為用戶提供真誠的服務(wù)。我們深信只要達到每一位用戶的要求,就會得到認(rèn)可,從而選擇與我們長期合作。這樣,我們也可以走得更遠!

看到另一篇C#解析Json的類 的文章現(xiàn)在json因為輕型,越來越流行,部門內(nèi)部的數(shù)據(jù)標(biāo)準(zhǔn)趨向于json,所以開始學(xué)習(xí)。本次工作內(nèi)容是要將以下數(shù)據(jù)解析成.Net可以使用的數(shù)據(jù),返回的數(shù)據(jù)除了header,其他的都是可變的,也就是說結(jié)構(gòu)不是固定的。完全由用戶選擇,所以選擇了生成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.          ///  
  26.  
  27.          /// 返回的數(shù)據(jù)結(jié)構(gòu)定義,無數(shù)據(jù)  
  28.  
  29.          ///  
  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.          ///  
  46.  
  47.          /// 返回的數(shù)據(jù),格式為DataTable,結(jié)構(gòu)和FieldDefine中的結(jié)構(gòu)一樣  
  48.  
  49.          ///  
  50.  
  51.          public DataTable RetrunData  
  52.  
  53.          {  
  54.  
  55.              get { return retrunData; }  
  56.  
  57.              set { retrunData = value; }  
  58.  
  59.          }  
  60.  
  61.  
  62.  
  63.          ///  
  64.  
  65.          /// 將json數(shù)據(jù)轉(zhuǎn)換為定義好的對象,數(shù)據(jù)轉(zhuǎn)換為DataTable  
  66.  
  67.          ///  
  68.  
  69.          ///  name="jsonText"> 
  70.  
  71.          ///  
  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, object> JsonData = (Dictionary, object>)s.DeserializeObject(jsonText);  
  84.  
  85.              Dictionary, object> dataSet = (Dictionary, object>)JsonData["dataSet"];  
  86.  
  87.              Dictionary, object> header = (Dictionary, object>)dataSet["header"];  
  88.  
  89.              Dictionary, object> fieldDefine = (Dictionary, object>)dataSet["header"];  
  90.  
  91.              Dictionary, object> data = (Dictionary, 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, object> dicFieldDefine = (Dictionary, object>)dataSet["fieldDefine"];  
  108.  
  109.              foreach (KeyValuePair, 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, object> val = (Dictionary, object>)ob;  
  128.  
  129.                  DataRow dr = gsr.RetrunData.NewRow();  
  130.  
  131.                  foreach (KeyValuePair, 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.          ///  
  148.  
  149.          /// 數(shù)據(jù)文件頭定義  
  150.  
  151.          ///  
  152.  
  153.          public class Header  
  154.  
  155.          {  
  156.  
  157.              private string version;  
  158.  
  159.              ///  
  160.  
  161.              /// 版本  
  162.  
  163.              ///  
  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.              ///  
  178.  
  179.              /// 結(jié)果碼,0為正常,否則為有錯誤  
  180.  
  181.              ///  
  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.              ///  
  196.  
  197.              /// 如果ReturnCode為非0時的錯誤信息  
  198.  
  199.              ///  
  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.              ///  
  214.  
  215.              /// 查詢結(jié)果總行數(shù)  
  216.  
  217.              ///  
  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.              ///  
  232.  
  233.              /// 返回的數(shù)據(jù)行數(shù)  
  234.  
  235.              ///  
  236.  
  237.              public int ReturnRows  
  238.  
  239.              {  
  240.  
  241.                  get { return returnRows; }  
  242.  
  243.                  set { returnRows = value; }  
  244.  
  245.              }  
  246.  
  247.          }  
  248.  
  249.      }  
  250.  

標(biāo)題名稱:探索非同凡響的Json數(shù)據(jù)格式說明
文章出自:http://www.dlmjj.cn/article/coihoed.html