Does anyone know what he's trying to say about the error he makes?
The JSON you are trying to parse has a detail: the first character is a {
key instead of a [
, so you will interpret an object instead of a array . The correct way to interpret it would be like this:
var jObject = JObject.Parse(json); // Interpreta el JSON en un objeto sin clase
var jToken = jObject.GetValue("objecto"); // Obtienes el valor de "objecto"
Objecto obj = jToken.ToObject(typeof(Objecto)); // Lo parsea a una instancia de tu clase
List<Answer> answers = obj.answer; // Accedes a la lista de "Answer"
Based on this answer in English .
The json starts with a property called "Objecto"
but you're trying to deserialize a json of type List<Objecto>
and obviously this type does not have a property called asi.
Create a class that contains a property of type Lista<Objecto>
:
public class MiJson{
public List<Objeto> objeto { get; set;}
}
Then you would replace:
var answers = JsonConvert.DeserializeObject<List<Objeto>>(json);
By:
var answers = JsonConverter.DeserializeObject<MiJson>(json).objeto;