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