I've been reading threads about deserializing json and tried a number of ways to achieve it but can't seem to make this work. Here's what I've done so far:
Class
public class oVesselMovement : oVMLocation, IWPConditions, IVessel, IStatus
{
public int wpID { get; set; }
public string charts { get; set; }
public string latNS { get; set; }
public string longEW { get; set; }
public string course { get; set; }
public double toNextWPNM { get; set; }
public double toGoNM { get; set; }
public string eda { get; set; }
public string eta { get; set; }
}
Root Class
public class RootVM
{
public List<oVesselMovement> jsnObj { get; set; }
}
JSON
{"jsnObj":[{"vmID":"1","charts":"2111","latNS":"10°29.10 N","longEW":"123°25.83 E","course":"420°","toNextWPNM":0,"toGoNM":"27","eda":"12-15-2016","eta":"11:01"},{"vmID":"2","charts":"2211","latNS":"11°29.10 N","longEW":"124°25.83 E","course":"420°","toNextWPNM":0,"toGoNM":"27","eda":"12-15-2016","eta":"11:01"}]}
Deserialization
[WebMethod]
public void saveVMDT(string jsnObj)
{
RootVM rootObj = new JavaScriptSerializer().Deserialize<RootVM>(jsnObj);
foreach (var obj in rootObj.jsnObj)
{
try
{
...
}
I've also tried converting the List<oVesselMovement> jsnObj { get; set; } to
oVesselMovement[] jsnObj but to no avail.
I keep getting this error:
"{"Message":"Type \u0027System.String\u0027 is not supported for deserialization of an array."....
Any help would be appreciated.
toGoNM is a string, not a number. You need to use the proper types, fix it either on the C# side, or the JSON side. You have wpID in the C# class, but vmID in the JSON; and again, with the wrong type.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With