我的程序正在接收json文件输入,该文件由内部的嵌套数组组成。 我设法在不使用数组的情况下反序列化json,但是当数组内部出现问题时。
我的Json文件:
[
{ "ReportType": "Manual",
"ReportDate": "09/05/2019",
"Department": "IT",
"Branch": "CT",
"Category": "Account Management",
"SubCategory": "A/C Opening",
"Title": "Online Onboarding",
"Attachments": [
{
"AttachmentName": "Attachment 1",
"Content": "Content 1",
}
{
"AttachmentName": "Attachment 2",
"Content": "Content 2",
}
{
"AttachmentName": "Attachment 3",
"Content": "Content 3",
}
]
}
]
我的模特:
public class DMSAccountOpeningServiceModel
{
public string ReportType;
public DateTime ReportDate;
public string Department;
public string Branch;
public string Category;
public string SubCategory;
public string Title;
public AttachmentServiceModel[] Attachments;
}
public class AttachmentServiceModel
{
public string AttachmentName;
public string Content;
}
我的代码:
public List<DMSAccountOpeningServiceModel> GetAttachmentJson(string attachment)
{
List<DMSAccountOpeningServiceModel> items;
using (StreamReader r = new StreamReader(attachment))
{
string json = r.ReadToEnd();
items = JsonConvert.DeserializeObject<List<DMSAccountOpeningServiceModel>>(json);
}
return items;
}}
我遇到错误:“在解析值后遇到意外字符:{。路径'[0] .Attachments [0]',第14行,位置3。”