Trying to deserialize the following json string:
string json = "{\"d\":{\"__metadata\":{\"id\":\"http://my.dev.int:8000/sap/opu/odata/sap/ZFIORI_SERIAL_NUMBERS_SRV/MATERIALSet('250')\",\"uri\":\"http://my.dev.int:8000/sap/opu/odata/sap/ZFIORI_SERIAL_NUMBERS_SRV/MATERIALSet('250')\",\"type\":\"ZFIORI_SERIAL_NUMBERS_SRV.MATERIAL\"},\"MATNR\":\"250\",\"MAKTX\":\"X:K10/MF250\"}}";
into Class Object
namespace Scanner.Model
{
public class Material
{
public string MATNR { get; set; }
public string MAKTX { get; set; }
}
}
I have tried using many ways including :
Material material = JsonSerializer.Deserialize<Material>(json, new JsonSerializerOptions
{
PropertyNameCaseInsensitive = true,
IgnoreNullValues = true,
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
});
Console.WriteLine(material.MATNR); //expected output: 250
Console.WriteLine(material.MAKTX); //expected output: X:K10/MF250
But material.MATNR and material.MAKTX are always null .