0
我试图加载与我收到的JSON网格。这是我在Home.cs
代码:C#与json加载网格
private void getTickets()
{
try
{
string urlName = "tickets";
string method = "GET";
string json = null;
HttpStatusCode statusCode = HttpStatusCode.Forbidden;
Tickets data = null;
RestClient client = RequestClient.makeClient();
MakeRequest request = new MakeRequest(null, null, urlName, method);
IRestResponse response = client.Execute(request.exec());
statusCode = response.StatusCode;
json = response.Content;
var ticketWrapper = JsonConvert.DeserializeObject<TicketWrapper>(json);
if ((int)statusCode == 200)
{
gridTicket.DataSource = ticketWrapper.tickets;
}
else
{
MessageBox.Show("error");
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
票务包装类
class TicketWrapper
{
public IEnumerable<Tickets> tickets { get; set; }
}
门票类
class Tickets
{
public int id;
public string title;
public string description;
public int user_id;
public int subject_id;
}
如果我调试我可以看到,我收到了JSON,但ticketWrapper
是空的什么可能是错误的?
你可以添加收到的json字符串到你的问题? – croxy