亚洲Aⅴ无码Av红楼在线观看_国产午夜福利涩爱AⅤ_国产sm调教一区二区三区_精品人妻一区二区三区不卡毛片

始創(chuàng)于2000年 股票代碼:831685
咨詢熱線:0371-60135900 注冊有禮 登錄
  • 掛牌上市企業(yè)
  • 60秒人工響應(yīng)
  • 99.99%連通率
  • 7*24h人工
  • 故障100倍補償
全部產(chǎn)品
您的位置: 網(wǎng)站首頁 > 幫助中心>文章內(nèi)容

大致闡述JSON數(shù)據(jù)格式的編寫與運行方式

發(fā)布時間:  2012/9/23 16:14:34

本文著重介紹下JSON數(shù)據(jù)格式的相關(guān)內(nèi)容說明,隨著JSON的不斷發(fā)展,編程的技巧也出現(xiàn)了不一樣的形式,對一些輕量級的數(shù)據(jù)交換格式進行編寫時,需要注意一些問題,比如輕量級的數(shù)據(jù)交換格式的問題。

 

本次工作內(nèi)容是要將以下數(shù)據(jù)解析成.Net可以使用的數(shù)據(jù),返回的數(shù)據(jù)除了header,其他的都是可變的,也就是說結(jié)構(gòu)不是固定的。完全由用戶選擇,所以選擇了生成DataTable。

SON數(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ù)結(jié)構(gòu)定義,無數(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,結(jié)構(gòu)和FieldDefine中的結(jié)構(gòu)一樣  
  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ù)轉(zhuǎn)換為定義好的對象,數(shù)據(jù)轉(zhuǎn)換為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.             }  

JSON數(shù)據(jù)格式使用方法:

  1. GeneralSearchResult gsr = new GeneralSearchResult();   
  2. gsr = GeneralSearchResult.GetTransformData(text);  

本文出自:億恩科技【www.allwellnessguide.com】

服務(wù)器租用/服務(wù)器托管中國五強!虛擬主機域名注冊頂級提供商!15年品質(zhì)保障!--億恩科技[ENKJ.COM]

  • 您可能在找
  • 億恩北京公司:
  • 經(jīng)營性ICP/ISP證:京B2-20150015
  • 億恩鄭州公司:
  • 經(jīng)營性ICP/ISP/IDC證:豫B1.B2-20060070
  • 億恩南昌公司:
  • 經(jīng)營性ICP/ISP證:贛B2-20080012
  • 服務(wù)器/云主機 24小時售后服務(wù)電話:0371-60135900
  • 虛擬主機/智能建站 24小時售后服務(wù)電話:0371-60135900
  • 專注服務(wù)器托管17年
    掃掃關(guān)注-微信公眾號
    0371-60135900
    Copyright© 1999-2019 ENKJ All Rights Reserved 億恩科技 版權(quán)所有  地址:鄭州市高新區(qū)翠竹街1號總部企業(yè)基地億恩大廈  法律顧問:河南亞太人律師事務(wù)所郝建鋒、杜慧月律師   京公網(wǎng)安備41019702002023號
      0
     
     
     
     

    0371-60135900
    7*24小時客服服務(wù)熱線