【发布时间】:2019-11-26 04:43:10
【问题描述】:
我有以下 JSON。
public class Code
{
public string ID { get; set; }
}
public class Country
{
public string CountryID { get; set; }
}
public class Complex
{
public Country Country { get; set; }
public Code Code { get; set; }
public string cText { get; set; }
}
public List<Complex> GetData()
{
List<Complex> Data = new List<Complex>();
Data.Add(new Complex() { Country = new Country() { CountryID = "Australia" }, Code = new Code() { ID = "AU" }, cText = "Australia" });
Data.Add(new Complex() { Country = new Country() { CountryID = "Bermuda" }, Code = new Code() { ID = "BM" }, cText = "Bermuda" });
Data.Add(new Complex() { Country = new Country() { CountryID = "Canada" }, Code = new Code() { ID = "CA" }, cText = "Canada" });
Data.Add(new Complex() { Country = new Country() { CountryID = "France" }, Code = new Code() { ID = "FR" }, cText = "France" });
return Data;
}
我需要从给定的复杂键(“Country.CountryID”)中获取 CountryID 的值。 我尝试使用 c# 中的 TryGetValue 方法获取值。这是行不通的。 我想我需要拆分密钥并处理复杂的 JSON 并找到嵌套的结果。 您能否建议如何从给定的复杂键中获取复杂对象的值?
【问题讨论】:
-
试试
Dictionary<String,Complex>?