Tengo problemas para deserializar una matriz en .NET MVC3, cualquier ayuda sería apreciada.JavaScriptSerializer.Deserialize array
He aquí el fragmento de código:
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);
}
Aquí está el subconjunto de la cadena de datos devuelto por JSON como jsonData. Eliminé campos adicionales.
"[
{\"id\":33,\"order_id\":230025,...},
{\"id\":34,\"order_id\":230025,...}
]"
Éstos son los objetos:
[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; }
...
}
que estoy recibiendo este error:
"Type 'Pxo.Models.BigCommerce.BigCommerceOrderProducts' is not supported for deserialization of an array.
¿Alguna idea?
¿Está tu cadena json envuelta en un objeto .NET? échale un vistazo aquí: http://stackoverflow.com/questions/402996/deserializing-json-objects-as-listtype-not-working-with-asmx-service – JoJa