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

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

開發(fā)
現(xiàn)在JSON數(shù)據(jù)格式因?yàn)檩p型,越來越流行,部門內(nèi)部的數(shù)據(jù)標(biāo)準(zhǔn)趨向于json,所以開始學(xué)習(xí),現(xiàn)在就對(duì)JSON數(shù)據(jù)格式進(jìn)行研究。

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

本次工作內(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)換為定義好的對(duì)象,數(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);  
責(zé)任編輯:chenqingxiang 來源: CSDN
相關(guān)推薦

2014-08-12 10:15:42

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

2024-04-15 13:13:04

PythonJSON

2010-01-06 14:04:55

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

2010-01-07 16:29:33

使用Json

2009-09-07 19:02:07

JSON是什么

2010-01-07 17:48:02

JSON結(jié)構(gòu)

2013-03-27 10:51:44

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

2011-04-11 09:48:59

AjaxWEB服務(wù)

2010-01-08 15:30:15

JSON格式舉例

2010-01-06 17:06:05

Json格式

2010-01-05 17:35:09

JSON數(shù)組格式

2024-11-12 12:08:06

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

2024-12-19 00:12:02

APIJSON數(shù)據(jù)

2022-06-05 14:57:35

發(fā)送釘釘運(yùn)維架構(gòu)

2009-11-26 17:02:29

VS2003配置

2010-01-07 09:31:27

Json數(shù)據(jù)異常

2010-01-08 09:03:38

返回JSON數(shù)據(jù)

2017-03-27 14:58:03

MapReduce數(shù)據(jù)類型數(shù)據(jù)格式

2009-11-27 13:45:02

Tomcat for

2010-02-04 13:52:30

Android ap
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)