Pour une raison quelconque, la chaîne JSON suivante crée le nombre correct d'enregistrements dans le tableau d'objets personnalisés, mais ne remplit PAS les objets du tableau avec et values. Aide appréciée!Le tableau JSON ne se remplit pas
JSON cordes
{
"Grids": [{ "CommitImporterGrid": {"CostDivisionCode": "DL", "CostDivisionKey": 5, "CostDivisionName": "Direct Labor", "SourceType": "Contractor", "CommitDollars": 202, "CommitHours": 113.12, "PercentComplete": 50.00, "TaxRate": 0, "IohRate": 0.01, "ConditionerRate": 0}}],
"ProjectKey": 571,
"AsOf": "1/1/2008 11:59:59 PM",
"WbsKey": 1327,
"FcrGroupKey": 26,
"ContractorKey": 11
}
désérialiseur
protected void btnSave_Click(object sender, EventArgs e)
{
JavaScriptSerializer serializer = new JavaScriptSerializer();
JsonViewer view = serializer.Deserialize<JsonViewer>(txtJson.Value);
// The LIST in the "view" object HAS records, but NO DATA?
}
Les classes personnalisées
public class JsonViewer
{
public JsonViewer()
{ }
public List<CommitImporterGrid> Grids { get; set; }
public Int32 ProjectKey { get; set; }
public String AsOf { get; set; }
public Int32 WbsKey { get; set; }
public Int32 FcrGroupKey { get; set; }
public Int32 ContractorKey { get; set; }
}
public class CommitImporterGrid
{
public CommitImporterGrid()
{ }
public String CostDivisionCode { get; set; }
public Int32 CostDivisionKey { get; set; }
public String CostDivisionName { get; set; }
public String SourceType { get; set; }
public Decimal CommitDollars { get; set; }
public Decimal CommitHours { get; set; }
public Decimal PercentComplete { get; set; }
public Decimal TaxRate { get; set; }
public Decimal IohRate { get; set; }
public Decimal ConditionerRate { get; set; }
}
Ouais, il semble être un tableau avec un objet, pas vraiment un tableau du tout .... –
RÉPONSE PLUS RAPIDE JAMAIS !!!! TANKS BEAUCOUP ... J'ai corrigé le JSON et ça marche super! –
Passez une bonne journée! –