To get the json
{"d":{"media":12.108320606149539,"lote":"","Opcao":[{"__type":"Model","leitura":70,"producao":1579981660130}],"sinal":"Up"}}
and turn it into an object you can use the following code:
obs: []
indicates array, you can read more here in this response
class Obj
{
public D D { get; set; }
}
class D
{
public string Media { get; set; }
public string Lote { get; set; }
public string Sinal { get; set; }
public List<Opcao> Opcao { get; set; }
}
class Opcao
{
public string __type { get; set; }
public string Leitura { get; set; }
public string Producao { get; set; }
}
Then, if your project does not already have it, download the library Newtonsoft.Json
(it is available via nuget )
and make Deserialize
of json.
In the example below I saved it in a string
class Program
{
static void Main(string[] args)
{
string json = @"{'d':{'media':12.108320606149539,'lote':'','Opcao':[{'__type':'Model','leitura':70,'producao':1579981660130}],'sinal':'Up'}}";
Obj myObj = new Obj();
myObj = JsonConvert.DeserializeObject<Obj>(json);
Console.WriteLine(myObj.D.Media);
}
}
You can see it working at .NET Fiddle