Jsonデータ変換
6968 ワード
using System.Web.Script.Serialization;//逆シーケンス化Collections;using System.Runtime.Serialization.Json;using Newtonsoft.Json;using Newtonsoft.Json.Converters;using System.IO;using System.Collections.Generic;
以上のネーミングスペースの導入
以上のネーミングスペースの導入
/// <summary>
/// JSON
/// </summary>
public static T JsonDeserialize<T>(string jsonString)
{
DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(T));
MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(jsonString));
T obj = (T)ser.ReadObject(ms);
return obj;
}
public class checkinfo
{
public string code { get; set; }
public string checkContent { get; set; }
public string checkResult { get; set; }
public string remark { get; set; }
}
public class checkinfolist
{
public List<checkinfo> list { get; set; }
}
//
checkinfolist checkinfomodel = JsonDeserialize<checkinfolist>(info);
// json
string sysIds = "";// id
string txtDevicename = "";
string txtDevicemodel = "";
string txtcheckPosition = "";
if (context.Request.QueryString["sysIds"] != null) { sysIds = context.Request.QueryString["sysIds"]; }
if (context.Request.QueryString["txtDevicename"] != null) { txtDevicename = context.Request.QueryString["txtDevicename"]; }
if (context.Request.QueryString["txtDevicemodel"] != null) { txtDevicemodel = context.Request.QueryString["txtDevicemodel"]; }
if (context.Request.QueryString["txtcheckPosition"] != null) { txtcheckPosition = context.Request.QueryString["txtcheckPosition"]; }
DataSet emps5 = emp2.GetDeviceCheckList(sysIds, txtDevicename, txtDevicemodel, txtcheckPosition, intPageSize, intCurrentPage);
ReturnValue = "{\"total\":" + emps5.Tables[1].Rows[0][0].ToString() + ", \"rows\":";
ReturnValue += JsonConvert.SerializeObject(emps5.Tables[0], new DataTableConverter());
ReturnValue += "}";