I need to serialize/deserialize save/get in this JSON type in a Windows Forms C# project.
This project is used to save information from CAN variables.
[
{
"Nome": "Esp 03",
"Local": "Praça,
"IP": "192.168.1.212",
"Variables":[{
"Nome":"RPM",
"id":"0X12",
"Startbit": 1,
"Length": 3,
"Factor": 0.1,
"Offset":1
},
{
"Nome":"Pedal",
"id":"0X12",
"Startbit": 5,
"Length": 1,
"Factor": 1,
"Offset":0
}]
}
]
How can I do this?
I trying with this code:
namespace PuxadinhoSGE
{
class Variables
{
public string Nome { get; set; }
public int Id { get; set; }
public int Startbit { get; set; }
public int Length { get; set; }
public float Factor { get; set; }
public float Offset { get; set; }
}
class Dispostivo
{
public string Nome { get; set; }
public string Local { get; set; }
public string IP { get; set; }
public ListView Variables { get; set; }
public string JsonSerializar(Dispostivo device)
{
Dispostivo Temp = new Dispostivo();
Temp.Nome = device.Nome;
Temp.Local = device.Local;
Temp.IP = device.IP;
String defaultValues = JsonConvert.SerializeObject(Temp);
String defaultVariables = this.JsonSeriaLista(device.Variables)
String ResultJson = defaultValues+defaultVariables;
return ResultJson;
}
public string JsonSeriaLista(ListView lista)
{
var defaultVariables = JsonConvert.SerializeObject(lista, Formatting.Indented);
return defaultVariables.Equals(defaultVariables);
}
public static Dispostivo JsonDesserializar(string Json)
{
return JsonConvert.DeserializeObject<Dispostivo>(Json);
}
}
}
But, I don’t get the correct, expected result. Any idea how to get the correct response?
4