c# gridView json中的多个对象
本文关键字:对象 gridView json | 更新日期: 2023-09-27 18:09:40
我在我的网格中显示成功的数据:
:
形式:
json = response.Content;
var ticketWrapper = JsonConvert.DeserializeObject<TicketWrapper(json);
TicketWrapper:
class TicketWrapper
{
public IEnumerable<Tickets> tickets { get; set; }
}
门票:
class Tickets
{
public int id { get; set; }
public string title { get; set; }
public string description { get; set; }
}
Json: {
"tickets": [
{
"id": 1,
"title": "Error bij compileren.",
"description": "Bij het compileren van mijn c# applicatie krijg ik een error. ",
"user_id": 1,
"subject_id": 1,
"status_id": 1,
"status": {
"id": 1,
"name": "In afwachting"
},
"subject": {
"id": 1,
"subject": "C#"
},
"user": {
"id": 1,
"name": "test",
"email": "test@gmail.com",
"company": "production",
"role_id": 1,
"created_at": null,
"updated_at": "2016-09-08 08:22:07"
}
}
]
}
我的问题是:
如何表示user
的name
。我已经试过这样做了:
class Tickets
{
public int id { get; set; }
public string title { get; set; }
public string description { get; set; }
}
您的Ticket
类不完整。
将Json粘贴到http://json2csharp.com返回这个类层次结构(编辑以删除多余的数据)
public class Ticket
{
public int id { get; set; }
public string title { get; set; }
public string description { get; set; }
public Status status { get; set; }
public Subject subject { get; set; }
public User user { get; set; }
}
public class RootObject
{
public List<Ticket> tickets { get; set; }
}
public class Status
{
public int id { get; set; }
public string name { get; set; }
}
public class Subject
{
public int id { get; set; }
public string subject { get; set; }
}
public class User
{
public int id { get; set; }
public string name { get; set; }
public string email { get; set; }
public string company { get; set; }
public int role_id { get; set; }
public object created_at { get; set; }
public string updated_at { get; set; }
}
一旦反序列化到此,就可以通过ticket.User.name