I need to Serealize/Desseralize Save/Get in this json type in on Windows Forms C# project:
This project is used to save informations from CAN-Variables
[{
“Nome”: “Esp 03”,
“Local”: “Praça,
“IP”: “192.168.1.212”,
“Variables”:[{
“Nome”:”RPM”,
“id”:”0X12″,
“Startbit”: 1,
“Lenght”: 3,
“Factor”: 0.1,
“Offset”:1
},
{
“Nome”:”Pedal”,
“id”:”0X12″,
“Startbit”: 5,
“Lenght”: 1,
“Factor”: 1,
“Offset”:0
}]
}]
How i can make this?
I trying ins this form:
namespace PuxadinhoSGE
{
class Variables
{
public string Nome { get; set; }
public int Id { get; set; }
public int Startbit { get; set; }
public int Lenght { 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 receive give the correct result.
Any Idea to give the correct response?