.NET MVC3で配列をデシリアライズする際に問題が発生しました。ここでJavaScriptSerializer.Deserialize array
は、コードスニペットです:
using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
using (StreamReader reader = new StreamReader(response.GetResponseStream())) {
JavaScriptSerializer jsSerializer = new JavaScriptSerializer();
string jsonData = reader.ReadToEnd();
result = (BigCommerceOrderProducts)jsSerializer.Deserialize<BigCommerceOrderProducts>(jsonData);
}
ここjsonDataとしてJSONで返されたデータ列のサブセットです。余分なフィールドを削除しました。ここで
"[
{\"id\":33,\"order_id\":230025,...},
{\"id\":34,\"order_id\":230025,...}
]"
オブジェクトです:
[Serializable]
public class BigCommerceOrderProducts {
public List<BigCommerceOrderProduct> Data { get; set; }
}
[Serializable]
public class BigCommerceOrderProduct {
public int Id { get; set; }
public int Order_id { get; set; }
...
}
が、私はこのエラーを取得しています:
"Type 'Pxo.Models.BigCommerce.BigCommerceOrderProducts' is not supported for deserialization of an array.
任意のアイデア?
あなたのJSON文字列は.NETオブジェクトにラップされていますか?ここで見て:http://stackoverflow.com/questions/402996/deserializing-json-objects-as-listtype-not-working-with-asmx-service – JoJa