我有Deserialising一個JSON字符串列表的問題問題Deserialising JSON列出<T>
的TCProject如下:
[JsonObject(MemberSerialization.OptIn)]
public class TCProject
{
public override string ToString()
{
return Name;
}
[JsonProperty(PropertyName = "archived")]
public bool Archived { get; set; }
[JsonProperty(PropertyName = "description")]
public string Description { get; set; }
[JsonProperty(PropertyName = "href")]
public string Href { get; set; }
[JsonProperty(PropertyName = "id")]
public string Id { get; set; }
[JsonProperty(PropertyName = "name")]
public string Name { get; set; }
[JsonProperty(PropertyName = "webUrl")]
public string WebUrl { get; set; }
}
JSON字符串如下所示:
{"project":[{"name":"GCUK","id":"project11","href":"/httpAuth/app/rest/projects/id:project11"},{"name":"Interiors In Spain","id":"project3","href":"/httpAuth/app/rest/projects/id:project3"}]}
到字符串轉換的代碼如下:
public IEnumerable<TCProject> GetAllProjects()
{
var uri = _connection.CreateUri("/httpAuth/app/rest/projects");
var request = _connection.Request(uri);
var projects = JsonConvert.DeserializeObject<List<TCProject>>(request);
return projects;
}
我得到異常:
Newtonsoft.Json.JsonSerialisationException:{ 「無法反序列化JSON對象轉換型 'System.Collections.Generic.List`1 [TCProject]'」}
那裏一定是東西很容易,我很想念 - 任何人有任何想法?
是什麼,你接收到這個樣子的方法? – jcolebrand
整個方法現在存在 - 的_connection.Request只返回一個JSON字符串 - 它沒有做什麼特別的吧 – stack72
哦,我纔剛剛意識到這是一般Silverlight的問題..我永遠不會做的Silverlight ...無法這裏弄清楚爲什麼我不能得到的東西來解決VS ... – jcolebrand