C# 使用JSON.net反序列化Api对象
让我解释一下我的问题。 所以我有JSON:C# 使用JSON.net反序列化Api对象,c#,json,json.net,deserialization,C#,Json,Json.net,Deserialization,让我解释一下我的问题。 所以我有JSON: {"num":20, "meta":[{"id":312, "identif":{"type":true,"status":false}}}]} 我目前正在抓取元id字段,其中包含: var id = JsonConvert.DeserializeObject<typeObj> (returnJSON(ApiUrl)).meta[0].id; var id=JsonConvert.DeserializeObjec
{"num":20, "meta":[{"id":312, "identif":{"type":true,"status":false}}}]}
我目前正在抓取元id字段,其中包含:
var id = JsonConvert.DeserializeObject<typeObj>
(returnJSON(ApiUrl)).meta[0].id;
var id=JsonConvert.DeserializeObject
(returnJSON(ApiUrl)).meta[0].id;
参考类别:
class typeObj
{
public int num {get; set; }
public List<metatypes> meta {get; set;}
}
class metatypes
{
public int id {get; set;}
}
classtypeobj
{
公共int num{get;set;}
公共列表元{get;set;}
}
类元类型
{
公共int id{get;set;}
}
但问题不在这里。我正在尝试从meta获取indentif status元素
我曾尝试将列表放入元类型中,如:
class metatypes
{
public int id {get; set;}
public List<idtypes> identif {get; set;}
}
class idtypes
{
public bool type {get; set;}
public bool status {get; set;}
}
类元类型
{
公共int id{get;set;}
公共列表标识符{get;set;}
}
类ID类型
{
公共布尔类型{get;set;}
公共布尔状态{get;set;}
}
称之为:
var id = JsonConvert.DeserializeObject<typeObj>
(returnJSON(ApiUrl)).meta[0].identif[0].status;
var id=JsonConvert.DeserializeObject
(returnJSON(ApiUrl)).meta[0]。identif[0]。状态;
但当我尝试这个时,它会返回
'无法将当前JSON对象(例如{“name”:“value”})反序列化为'System.Collections.Generic.List`1'类型
环顾四周,找不到我的问题的直接解决方案。所需结构的json不正确: 给定类别:
class typeObj
{
public int num {get; set; }
public List<metatypes> meta {get; set;}
}
class metatypes
{
public int id {get; set;}
public List<idtypes> identif {get; set;}
}
class idtypes
{
public bool type {get; set;}
public bool status {get; set;}
}
对于讨论中的json,您的类应该如下所示:()
classtypeobj
{
公共int num{get;set;}
公共列表元{get;set;}
}
类元类型
{
公共int id{get;set;}
公共idtypes identif{get;set;}
}
类ID类型
{
公共布尔类型{get;set;}
公共布尔状态{get;set;}
}
你是个救生员!非常感谢。真不敢相信这就是全部!
{"num":20, "meta":[{"id":312, "identif":[{"type":true,"status":false}]}]}
class typeObj
{
public int num {get; set; }
public List<metatypes> meta {get; set;}
}
class metatypes
{
public int id {get; set;}
public idtypes identif {get; set;}
}
class idtypes
{
public bool type {get; set;}
public bool status {get; set;}
}