请帮助我,我是新的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