简体   繁体   中英

JSON deserialization error on integer types - C#

I am implementing for the first time a POST in WebAPI from an Angular client that receives a JObject which I then deserialize to my objects of interest. But when I check the resulting object I see that all fields are appropriately filled except those meant to be integers.

This is part of my POST method

 // POST: api/PresupuestosApi
    [ResponseType(typeof(Presupuesto))]
    public async Task<IHttpActionResult> PostPresupuesto([FromBody]JObject presupuesto)
    {
        if (!ModelState.IsValid)
        {
            return BadRequest(ModelState);
        }
        try
        {
            Presupuesto p = presupuesto.ToObject<Presupuesto>();

My JSON looks like this:

{  
"sTitulo": "Agentasa",  
"cSolicitante": 
{
    "eRol": "SOLICITANTE",
    "sEmail": "bla@sdlfkjsf.com",
    "iTelefono": "122299935",
    "sNombre": "Clau",
    "sApellido": "Clau"  
},  
"cTrabajo": 
{
    "SNombreTrabajo": "Agenda"  

},  
"sMaterial": "sadsa",  
"sDimAbierto": "12x22",  
"sDimCerrado": "12x155",  
"sImpresion": "Una cara",  
"fGramaje": 12.5,  
"iCantidad": 122,  
 }

And my Presupuesto class is this:

public class Presupuesto
{
    private int iIdPresupuesto;
    private string sTitulo;
    private Solicitante cSolicitante;
    private Trabajo cTrabajo;
    private string sMaterial;
    private string sDimAbierto;
    private string sDimCerrado;
    private float fGramaje;
    private string sImpresion;
    private int iCantidad;
  }

So, when debugging I see this:

p对象

I am lost as to why it is correctly parsing every other type but int. Any suggestions on this subject? I need to emphasize I have never worked with WebAPI before.

0x0000007a in Hex = 122 in Dec. Check your debugger settings. Debugger seems to be set to display integers in Hex.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM