日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

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

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
大致闡述JSON數(shù)據(jù)格式的編寫與運(yùn)行方式

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

溫江網(wǎng)站建設(shè)公司成都創(chuàng)新互聯(lián)公司,溫江網(wǎng)站設(shè)計(jì)制作,有大型網(wǎng)站制作公司豐富經(jīng)驗(yàn)。已為溫江上千提供企業(yè)網(wǎng)站建設(shè)服務(wù)。企業(yè)網(wǎng)站搭建\成都外貿(mào)網(wǎng)站建設(shè)公司要多少錢,請(qǐng)找那個(gè)售后服務(wù)好的溫江做網(wǎng)站的公司定做!

本次工作內(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.         ///  
  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)換為定義好的對(duì)象,數(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.             }  

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

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

分享文章:大致闡述JSON數(shù)據(jù)格式的編寫與運(yùn)行方式
分享網(wǎng)址:http://www.5511xx.com/article/cdceeds.html