Tôi gặp sự cố khi deserializing một mảng trong .NET MVC3, mọi trợ giúp sẽ được đánh giá cao.JavaScriptSerializer.Deserialize array
Dưới đây là đoạn mã:
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);
}
Dưới đây là tập hợp con của chuỗi dữ liệu trả về bởi JSON như jsonData. Tôi đã xóa thêm các trường.
"[
{\"id\":33,\"order_id\":230025,...},
{\"id\":34,\"order_id\":230025,...}
]"
Dưới đây là các đối tượng:
[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; }
...
}
Tôi nhận được lỗi này:
"Type 'Pxo.Models.BigCommerce.BigCommerceOrderProducts' is not supported for deserialization of an array.
Bất kỳ ý tưởng?
là chuỗi json của bạn được bao bọc trong một đối tượng .NET? có một cái nhìn ở đây: http://stackoverflow.com/questions/402996/deserializing-json-objects-as-listtype-not-working-with-asmx-service – JoJa