我正在尝试从平面json中获取所有元素。我可以看到多个项目的计数,但是看不到每个列表属性的值。
JSON:
{
"Key":"C23432151461561",
"OrderId": 129012092109,
"SteamId":12341234321,
"AppId":1234132,
"ItemCount":2,
"Language":"en",
"Currency":"CAD",
"itemid[0]":1,
"qty[0]":2,
"amount[0]":12,
"description[0]":"majora's mask",
"itemid[1]":1,
"qty[1]":2,
"amount[1]":12,
"description[1]":"mario's hat",
}
模型
class Descriptions
{
public string descriptions { get; set; }
}
public class Amounts
{
public int amounts { get; set; }
}
public class Qtys
{
public int qtys { get; set; }
}
public class Items
{
public int itemids { get; set; }
}
public class InitTxn
{
public string key { get; set; }
public int orderid { get; set; }
public long steamid { get; set; }
public int appid { get; set; }
public int itemcount { get; set; }
public string language { get; set; }
public string currency { get; set; }
public List<Items> itemid { get; set; }
public List<Qtys> qty { get; set; }
public List<Amounts> amount { get; set; }
public List<Descriptions> description { get; set; }
}
发布方法
[System.Web.Http.HttpPost]
public string InitRequest([FromBody] InitTxn initTxn)
{}
我需要能够看到List属性的值。谢谢
答案 0 :(得分:1)
您的示例一切正常,但数据模型类除外。您使用中间类(例如Qtys
或Items
),但是json仅公开原始类型的数组。而不是具有属性XXX的对象数组。
总而言之,您的模型只需要看起来像下面的类:
public class InitTxn
{
public string key { get; set; }
public int orderid { get; set; }
public long steamid { get; set; }
public int appid { get; set; }
public int itemcount { get; set; }
public string language { get; set; }
public string currency { get; set; }
public List<int> itemid { get; set; }
public List<int> qty { get; set; }
public List<int> amount { get; set; }
public List<string> description { get; set; }
}