using Newtonsoft.Json;
using 嵌套List排序;
//示例list
var exampleString =
"{\"code\":1,\"msg\":\"[OK]AI诊断成功!\",\"diagnoseJson\":{\"disease\":{\"zhongda\":[[\"胆癌(胆囊癌胆总管癌胆囊肉瘤)\",0.00012]],\"changjian\":[[\"肝痞(脂肪肝)\",0.00365],[\"肝瘤(肝内囊肿、肝血管瘤)\",0.00064],[\"胆瘅(急性胆囊炎)\",0.01004]]}}}";
//需求根据diagnoseJson 中 changjian 中的数字进行排序取第一个对象
//将示例字符串转换为对象
var exampList = JsonConvert.DeserializeObject<ExampleDto>(exampleString);
//判断转换是否为空
if (exampList != null)
{
//排序并取出第一个对象list
var changjianList = exampList.diagnoseJson.disease.changjian.OrderByDescending(lst => lst[1]).FirstOrDefault();
//判断list不为空
if (changjianList != null)
{
//取出排序后第一个
var changjian = changjianList[0];
//输出
Console.WriteLine(changjian);
}
}
Console.ReadKey();
ExampleDto 类
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace 嵌套List排序
{
//如果好用,请收藏地址,帮忙分享。
public class Disease
{
/// <summary>
///
/// </summary>
public List<List<string>> zhongda { get; set; }
/// <summary>
///
/// </summary>
public List<List<string>> changjian { get; set; }
}
public class DiagnoseJson
{
/// <summary>
///
/// </summary>
public Disease disease { get; set; }
}
public class ExampleDto
{
/// <summary>
///
/// </summary>
public int code { get; set; }
/// <summary>
/// [OK]AI诊断成功!
/// </summary>
public string msg { get; set; }
/// <summary>
///
/// </summary>
public DiagnoseJson diagnoseJson { get; set; }
}
}
标签:set,get,changjian,List,嵌套,并取,using,public From: https://www.cnblogs.com/hanyiblog/p/17346106.html