1
我正在解析來自Citrix的Web服務的JSON響應。響應看起來像這樣JavaScript解析器異常解析JSON響應
[{\"webinarKey\":123456,\"subject\":\"Subject\",\"description\":\"Webinar Description. \",\"organizerKey\":123456,\"times\":[{\"startTime\":\"2012-05-08T16:00:00Z\",\"endTime\":\"2012-05-08T17:00:00Z\"}],\"timeZone\":\"America/New_York\"}]
我手動編輯的字符串,刪除識別信息,因此,如果存在丟失的報價或任何它是不相關的。
我跟着這個答案的例子,所以,但仍然遇到一個錯誤。
Deserializing JSON result with Json & JavaScriptSerializer
public class Webinars {
public string webinarKey;
public string subject;
public string description;
public string organizerKey;
public WebinarTimes[] times;
public string timeZone;
}
public class WebinarTimes {
public string startTime;
public string endTime;
}
JavaScriptSerializer jss = new JavaScriptSerializer();
var foo = jss.Deserialize<Webinars>(JSON);
我收到以下錯誤:Type 'Web.Site.Webinars' is not supported for deserialization of an array.
如果我沒看錯你需要使用jss.Deserialize>(JSON) –
@ClaudioRedi - 當然有幫助,解決了第一個錯誤,現在是新的錯誤是'WebinarTimes不支持數組的反序列化。' – mrtsherman
@ClaudioRedi - 修復,如果你發佈答案我會接受。必須修改'Webinars'以將'WebinarTimes'包含爲一個數組。 – mrtsherman