How to pass a JSON Object to a method in the webservice?

Asked

Viewed 127 times

2

I’m trying to pass a JSON Object to a method in my controller and I’m not getting it, the problem is that the email field always returns null.

How to do this ?

I’m trying like this.

JSON Object

{"UsuarioJsonModel": {"email":"[email protected]", "senha":"xxxxxx"}}

Model

public class UsuarioJsonModel 
{

    public long id                  { get; set; }         
    public String nome              {   get;set;}            
    public String email             {get;set;}    
    public String senha             {get;set;}   
    public int status               { get; set; } //1 ativo, 2 inativo, 0 aguardando
    public int tipo                 { get; set; } //1 painel, 2 aplicativos
    public String imagem            { get; set; }
    public int loginBy              { get; set; } //0 app, 1 facebook
    public UsuarioJsonModel() { }

}

Method that receives JSON Object

[WebMethod]
[HttpPost]
public JsonResult doLoginApp(UsuarioJsonModel model)
{ 
    jsonResposta.Add("status", "1");
    jsonResposta.Add("email", model.email);
    return Json(jsonResposta);
}

1 answer

2


You need to pass an object that has the properties defined in the model. In the current form, an object is being passed with the property UsuarioJsonModel and this property is the object you need.

Just change your JSON to

{ "email":"[email protected]", "senha":"xxxxxx" }

Browser other questions tagged

You are not signed in. Login or sign up in order to post.