我一直在閱讀有關反序列化json的線程,並嘗試了很多方法來實現它,但似乎無法完成此工作。 這是我到目前爲止已經完成:類型System.String不受數組支持
類
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; }
}
根類
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"}]}
反序列化
[WebMethod]
public void saveVMDT(string jsnObj)
{
RootVM rootObj = new JavaScriptSerializer().Deserialize<RootVM>(jsnObj);
foreach (var obj in rootObj.jsnObj)
{
try
{
...
}
我也試着轉換List<oVesselMovement> jsnObj { get; set; }
到 oVesselMovement[] jsnObj
但無濟於事。
我不斷收到此錯誤:
"{"Message":"Type \u0027System.String\u0027 is not supported for deserialization of an array."....
任何幫助,將不勝感激。
請嘗試[this](http://stackoverflow.com/a/25654220/5588347)。 –
使用Json.net。我試過它的代碼它的作品 – esiprogrammer