請幫助我,我是新的C#和JSON工作。我想使用newtonsoft命名空間反序列化C#中的json數據。反序列化數組json c#
這裏是我的課:
class lastResponse
{
public string type { get; set; }
public Metadata metadata { get; set; }
// public string[] course { get; set; }
public List<object> course { get; set; }
public string publisher { get; set; }
}
public class Metadata
{
public string bookID { get; set; }
public string title { get; set; }
public string filename { get; set; }
}
此代碼:
var errorMsg = JsonConvert.DeserializeObject<lastResponse>(downloader.LastResponse);
給了我這個錯誤:
"An unhandled exception of type 'Newtonsoft.Json.JsonSerializationException' occurred in Newtonsoft.Json.dll Additional information: Cannot deserialize the current JSON array (e.g. [1,2,3]) into type 'BookManager.lastResponse' because the type requires a JSON object (e.g. {"name":"value"}) to deserialize correctly."
請幫我找出我在這裏失蹤。
對我來說這似乎不太可能是*完整*錯誤。如果這是一個例外,請發佈完整的堆棧跟蹤。如果這是編譯時錯誤,請發佈完整的錯誤。 – 2015-02-06 10:33:00
可以顯示'downloader.LastResponse'這個'string' – 2015-02-06 10:33:53
@JonSkeet這是我得到的錯誤「Newtonsoft.Json.Json.dll中發生類型'Newtonsoft.Json.JsonSerializationException'的未處理異常 其他信息:不能將當前JSON數組(例如[1,2,3])反序列化爲類型'BookManager.lastResponse',因爲該類型需要JSON對象(例如{「name」:「value」})才能正確地反序列化。 – Red 2015-02-06 10:56:25