To catch the json
{"d":{"media":12.108320606149539,"lote":"","Opcao":[{"__type":"Model","leitura":70,"producao":1579981660130}],"sinal":"Up"}}
and turns it into object you can use the following code:
Obs: the []
indica array, you can read more here on reply
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 doesn’t already have it, download the library Newtonsoft.Json
(she is available via nuget)
and do the Deserialize
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);
}
}
It is possible to see working on .NET Fiddle
This json does not work. Apparently it is not complete. It has an extra "{" at the beginning, which is never closed, and a comma where it should not. Where are you getting it from?
– Francisco
sorry, you were right. json was not correct.
– Roberto Luiz Teixeira Rocha
follows the correct json: {"d":{"media":12.108320606149539,"lot":"","Option":[{"__type":"Model","reading":70,"production":1579981660130}],"signal":"Up"}}
– Roberto Luiz Teixeira Rocha