【发布时间】:2022-01-14 19:18:56
【问题描述】:
我有这个 Json 对象:
{
"ComplementoCartaPorte": [
{
"RFCImportador": "IJD840224QD2",
"Pedimentos": [
{
"NumPedimento": "80034680000518",
"Referencia": "REFPEDIMENTO1IN",
"Remesa": 1
},
{
"NumPedimento": "80034680000528",
"Referencia": "REFPEDIMENTO2A1",
"Remesa": 0
}
],
"Archivos": {
"FolioFiscal": "287d57c7-9132-4234-9268-28e984e7cdf1",
"PDF": "PD94",
"XML": "PD94"
}
},
{
"RFCImportador": "MJD960223MV9",
"Pedimentos": [
{
"NumPedimento": "80034680000519",
"Referencia": "REFPEDIMENTO3IN",
"Remesa": 1
},
{
"NumPedimento": "80034680000520",
"Referencia": "REFPEDIMENTO4A1",
"Remesa": 0
}
],
"Archivos": {
"FolioFiscal": "587d57c7-9133-4234-9268-28e984e7cdg7",
"PDF": "AM92",
"XML": "AM92"
}
}
]
}
我尝试将其反序列化为此类的 C# 对象:
// Top level class
public class ComplementoCartaPorte
{
// Only one field, an array
public Complemento[] Complemento { get; set; }
}
// Array elements of "Complemento" field
public class Complemento
{
public string RFCImportador { get; set; }
// Array Field
public Pedimento[] Pedimentos { get; set; }
public Archivo Archivos { get; set; }
}
// Array elements of "Pedimentos" field
public class Pedimento
{
public string NumPedimento { get; set; }
public string Referencia { get; set; }
public int Remesa { get; set; }
}
public class Archivo
{
public string FolioFiscal { get; set; }
public string PDF { get; set; }
public int XML { get; set; }
}
我尝试像这样反序列化(C#):
ComplementoCartaPorte comp = JsonConvert.DeserializeObject<ComplementoCartaPorte>(json_string);
“comp”结果对象的类型为“ComplementoCartaPorte”,但它只有一个“Complemento”类型的属性,即为空。我希望它是一个包含数据的“Complemento”对象数组。
有人可以解释一下吗?非常感谢。
【问题讨论】: