我想将我在Json文件中的数据放入我创建的对象中,但它只适用于json文件的第一部分。在这种情况下批处理。
我将Batch的所有数据都存入我的Batch对象。但是裁剪,筛选和包裹都是空的。
我需要做些什么来填补它们?
这是我的课程对象。
[DataContract(Namespace="Importer")]
public class Importer
{
[DataMember]
public List<Crop> Crop { get; set; }
[DataMember]
public List<Batch> Batch {get; set;}
[DataMember]
public List<Sift> Sift { get; set; }
[DataMember]
public List<Parcel> Parcel { get; set; }
我的Json文件。
{
"Batch": [
{ "iID": 4, "sDescription": "Afbroei" },
{ "iID": 5, "sDescription": "Hij" }
]
"Crop": [
{ "iID": 15, "sDescription": "Bloem" },
{ "iID": 16, "sDescription": "Bloem 222" },
{ "iID": 17, "sDescription": "TEST" }
]
"Sift": [
{ "iID": 5, "sDescription": "8-9", "iBolSize": 8 },
{ "iID": 6, "sDescription": "12-13", "iBolSize": 12 }
]
"Parcel": [
{ "iID": 3, "sDescription": "Hexapole", "sPlace": "Beverwijk", "sAddress": "", "sZipCode": "", "sPhoneNumber": "", "sInfo": "", "sEmail": "", "bActive": 1 }
]
}
我的反序列化代码。
public static void ImportDeSerializer()
{
DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(Importer));
MemoryStream stream1 = new MemoryStream();
using (FileStream file = new FileStream("D:/Projects/Hexateelt/ASP.NET_Hexateelt/Website/Imports/jsonImport.json", FileMode.Open, FileAccess.Read))
{
file.CopyTo(stream1);
stream1.Position = 0;
}
Importer import = (Importer)ser.ReadObject(stream1);
}
答案 0 :(得分:0)
在JSON对象中的每个属性后添加逗号:
{
"Batch": [
{ "iID": 4, "sDescription": "Afbroei" },
{ "iID": 5, "sDescription": "Hij" }
],
"Crop": [
{ "iID": 15, "sDescription": "Bloem" },
{ "iID": 16, "sDescription": "Bloem 222" },
{ "iID": 17, "sDescription": "TEST" }
],
"Sift": [
{ "iID": 5, "sDescription": "8-9", "iBolSize": 8 },
{ "iID": 6, "sDescription": "12-13", "iBolSize": 12 }
],
"Parcel": [
{ "iID": 3, "sDescription": "Hexapole", "sPlace": "Beverwijk", "sAddress": "", "sZipCode": "", "sPhoneNumber": "", "sInfo": "", "sEmail": "", "bActive": 1 }
]
}