Jul 11, 2012, 5:18 PM
[CLOSED] JSON deserialize model fields to one nested object
Hi, I try to find solution for this but unsuccessfully. Her is the problem:
In model of grid panel I have some model fields:
I need to deserialize on this way: ObracunskiPeriod_ID and ObracunskiPeriod_Naziv serialize to ObracunskiPeriod object:
How can I deserialize this?
In model of grid panel I have some model fields:
fields.Add(Html.X().ModelField().Name("ObracunskiPeriod_ID").Type(ModelFieldType.Int));
fields.Add(Html.X().ModelField().Name("ObracunskiPeriod_Naziv"));
To controller I send data as json string using parameter:Parameter stavke = new Parameter { Name = "pStavke", Value = "Ext.encode(App.GridPanelStavke.getRowsValues())", Mode = ParameterMode.Raw };
On server I try to deserialize json string to list of objects: public ActionResult SacuvajRacun(string p1, string pStavke)
{
List<StavkaDokumenta> _stavke = JSON.Deserialize<List<StavkaDokumenta>>(pStavke);
}
I need to deserialize on this way: ObracunskiPeriod_ID and ObracunskiPeriod_Naziv serialize to ObracunskiPeriod object:
public class ObracunskiPeriod
{
[JsonProperty(PropertyName = "ObracunskiPeriod_ID")]
public int Op_ID { get; set; }
[JsonProperty(PropertyName = "ObracunskiPeriod_Naziv")]
public string Op_Naziv { get; set; }
}
ObracunskiPeriod is one preoperty of StavkaDokumenta: public class StavkaDokumenta
{
public ObracunskiPeriod Sd_ObracunskiPeriod { get; set; }
}
How can I deserialize this?
Last edited by Daniil; Jul 12, 2012 at 12:26 PM.
Reason: [CLOSED]