我有一个返回此JSON代码的api:
[{"startDate":1409553000000,
"endDate":1409570100000,
"moduleCode":"#SPLUS0EBB2C",
"activityDescription":"User Interface Design (Tjuna)","staffMembers":[],
"locations":[{"id":"E404A902125255D3330455204193CC29","name":"HAA-H1-21","key":"14124","capacity":24,"url":null,"avoidConcurrencyLocationIds":[]}],
"studentSets":["INF3s","INF4a"],
"activityTypeName":"Other","activityTypeDescription":null,"notes":null,"highlighted":false,
"timetableKeys":["2013!studentsetgroup!9EEA55042B995043A2BC5739BF428E07"]}]
要反序列化我有这段代码:
var responseObject = await JsonConvert.DeserializeObjectAsync<Apicalls.Rooster>(json);
class Rooster
{
public string startDate { get; set; }
public string endDate { get; set; }
public string activityDescription { get; set; }
public locations[] locations { get; set; }
public string studentSets { get; set; }
}
public class locations
{
public string name { get; set; }
}
每次我尝试反序列化它都会产生一个错误,即无法反序列化json代码。任何人都可以帮我解决这个问题吗?
答案 0 :(得分:3)
<强>鸡强>
public class Rooster
{
public long startDate { get; set; }
public long endDate { get; set; }
public string moduleCode { get; set; }
public string activityDescription { get; set; }
public List<object> staffMembers { get; set; }
public List<Location> locations { get; set; }
public List<string> studentSets { get; set; }
public string activityTypeName { get; set; }
public object activityTypeDescription { get; set; }
public object notes { get; set; }
public bool highlighted { get; set; }
public List<string> timetableKeys { get; set; }
}
位置强>
public class Location
{
public string id { get; set; }
public string name { get; set; }
public string key { get; set; }
public int capacity { get; set; }
public object url { get; set; }
public List<object> avoidConcurrencyLocationIds { get; set; }
}
<强>代码:强>
var responseObject =
await JsonConvert.DeserializeObjectAsync<List<Apicalls.Rooster>>(json);
<强> Demo 强>