0

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": "[email protected]",
    "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 object

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.

8
  • There is only one int in your screenshot and it seems to have the same value as it has in the JSON. What exactly is the problem? Commented Jun 6, 2017 at 23:38
  • are you setting any content type header on the client side, specifically on the http.post method of ur angular app? And why dont u directly bind the posted values into a Presupuesto object? Commented Jun 6, 2017 at 23:40
  • @moreON The only int here is iCantidad, and it is being set to 0x0000007a (what is this? A memory location?). Shouldn't it be 122, like the int i submitted in the JSON? Commented Jun 6, 2017 at 23:49
  • 0x0000007a in Hex = 122 in Dec Commented Jun 6, 2017 at 23:50
  • 1
    @emmaielle check your debugger settings. stackoverflow.com/questions/3354453/… Commented Jun 6, 2017 at 23:54

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.