0
The name of your properties json
may be equal to the object you are receiving as already quoted(I find this particularly horrible, rs). I will show a more "elegant" way to resolve, using the Newtonsoft.Json
.
First install it in your project:
using Newtonsoft.Json;
Then on your object
public class RootObject
{
[JsonProperty("name")]
public string Name { get; set; }
[JsonProperty("lastname")]
public string Lastname { get; set; }
[JsonProperty("cpf")]
public string Cpf { get; set; }
[JsonProperty("birthDate ")]
public string BirthDate { get; set; }
[JsonProperty("motherName")]
public string MotherName { get; set; }
[JsonProperty("postalCode")]
public string PostalCode { get; set; }
[JsonProperty("adress")]
public string Adress { get; set; }
[JsonProperty("adressNumber")]
public string AdressNumber { get; set; }
[JsonProperty("complement")]
public string Complement { get; set; }
[JsonProperty("background")]
public string Background { get; set; }
[JsonProperty("graduations")]
public IEnumerable<Graduation> Graduations { get; set; }
}
public class Graduation
{
[JsonProperty("instituionName")]
public string InstituionName { get; set; }
[JsonProperty("grade")]
public string Grade { get; set; }
[JsonProperty("formationYear")]
public string FormationYear { get; set; }
}
Your Controller
[HttpPost]
public IActionResult Create([FromBody] RootObject obj)
{
// Faz algo aqui
return Ok();
}
And you’ll finally get the long-awaited result, hehe.
Friend tries to change the property "Graduation" to "Graduations" equal is in his class, it will only popular if the names are identical.
– Maycon F. Castro