处理json 数据

master
nodyang@aliyun.com 1 month ago
parent 91a8b511ec
commit 1fd3d68af8

@ -1,6 +1,10 @@
using System;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Text;
using Newtonsoft.Json;
#region << 版 本 注 释 >>
/*--------------------------------------------------------------------
@ -32,9 +36,25 @@ namespace SlnMesnac.RfidUpload.Model.apiParam
public string msg { get; set; }
public List<Object> @object { get; set; }
// public List<Object> @object { get; set; }
public bool IsSuccess => code == "200";
public List<T> ToObjectList<T>()
{
JObject job = JObject.Parse(body);
string str = job["retBody"]?["object"]?.ToString();
if (!string.IsNullOrEmpty(str))
{
List<T> institutionList = JsonConvert.DeserializeObject<List<T>>(str);
return institutionList;
}
return new List<T>();
}
public string body { get; set; }
public string body { get; set; }
public string code { get; set; }
public string csbCode { get; set; }

@ -72,9 +72,11 @@ namespace SlnMesnac.RfidUpload.UI
CsbResult res = csbHandleBusiness.findStationSequenceByCsb(_transferOrderInfo.ffjhNo, opBatch);
if (res.code == "200")
{
if (res.@object != null && res.@object.Count > 0)
if (res.IsSuccess)
{
List<Institution> institutionList = res.@object.ConvertAll(item => JsonConvert.DeserializeObject<Institution>(item.ToString()));
List<Institution> institutionList = res.ToObjectList<Institution>();
// res.@object.ConvertAll(item => JsonConvert.DeserializeObject<Institution>(item.ToString()));
int count = 1;
Console.WriteLine("机构信息:");
foreach (var institution in institutionList)

@ -139,9 +139,9 @@ namespace SlnMesnac.RfidUpload.UI.viewModel
MessageBox.Show(res.message);
if (res.code == "200")
{
if (res.@object != null && res.@object.Count > 0)
if (res.IsSuccess)
{
List<TransferOrderInfo> institutionList = res.@object.ConvertAll(item => JsonConvert.DeserializeObject<TransferOrderInfo>(item.ToString()));
List<TransferOrderInfo> institutionList = res.ToObjectList<TransferOrderInfo>();
TransferOrderInfoItems = new ObservableCollection<TransferOrderInfo>(institutionList);
}
}

Loading…
Cancel
Save