我正在尝试反序列化JSON,但仍然出现以下异常信息:
“无法将 System.String 转换为 SmartBookLibrary.ViewModel.BookJ1。”
描述:在当前网络请求的执行期间发生了未处理的异常。请查看堆栈跟踪以获取有关错误的详细信息以及错误在代码中的起源位置。异常详细信息:System.ArgumentException: 无法将 System.String 转换为 SmartBookLibrary.ViewModel.BookJ1。
这是我的JSON示例:
这是代码:
“无法将 System.String 转换为 SmartBookLibrary.ViewModel.BookJ1。”
描述:在当前网络请求的执行期间发生了未处理的异常。请查看堆栈跟踪以获取有关错误的详细信息以及错误在代码中的起源位置。异常详细信息:System.ArgumentException: 无法将 System.String 转换为 SmartBookLibrary.ViewModel.BookJ1。
这是我的JSON示例:
{
"authorfamily1": "von Goethe",
"authorname1": "Johann",
"authorsurname1": "Wolfgang",
"title": "Fausto I",
"extension": "epub",
"md5": "58cb1dd438bc6c6027fcda9e7729e5ee",
"isbn": "",
"descr": "",
"cover": "1"
},
{
"authorfamily1": "von Goethe 1",
"authorname1": "Johann",
"authorsurname1": "Wolfgang",
"title": "Fausto I",
"extension": "epub",
"md5": "58cb1dd438bc6c6027fcda9e7729e5ee",
"isbn": "",
"descr": "",
"cover": "1"
}
这是代码:
var json = System.IO.File.ReadAllText("/data1.json");
var courses = JsonConvert.DeserializeObject<Dictionary<string, BookJ1>>(json);
这是我的模型或虚拟机:
public class BookJ1
{
public string title { get; set; }
public string isbn { get; set; }
public string extension { get; set; }
public string authorfamily1 { get; set; }
public string authorname1 { get; set; }
public string md5 { get; set; }
public int cover { get; set; }
[AllowHtml]
[Column(TypeName = "text")]
public string descr { get; set; }
}