У меня проблема сейчас, я могу повторить это JSON со следующим кодом, но у меня не осталось значений для "libros", таких как "titulo", "author" et c. что со мной не так? или как я могу получить список "Libros" для правильной итерации. я использую RestSharp и
namespace ConsoleApp1
{
public class Libro
{
public int id { get; set; }
public string id_categoria { get; set; }
public string tipo { get; set; }
public string titulo { get; set; }
public string ruta { get; set; }
public string autor { get; set; }
public int estado { get; set; }
public string titular { get; set; }
public int size { get; set; }
public string detalles { get; set; }
public double precio { get; set; }
public string portada { get; set; }
public int ventas { get; set; }
public int oferta { get; set; }
public double precioOferta { get; set; }
public int entrega { get; set; }
public string fecha { get; set; }
}
public class Cate
{
public int id { get; set; }
public string categoria { get; set; }
public string ruta { get; set; }
public int estado { get; set; }
public int oferta { get; set; }
public int precioOferta { get; set; }
public int descuentoOferta { get; set; }
public string imgOferta { get; set; }
public string finOferta { get; set; }
public string fecha { get; set; }
public IList<Libro> libros { get; set; }
}
class Program
{
static void Main(string[] args)
{
var client = new RestClient("wwwwwwwww");
client.Timeout = -1;
var request = new RestRequest(Method.GET);
IRestResponse response = client.Execute(request);
Console.WriteLine(response);
Console.WriteLine("mostrar registros");
Libro[] resultados = JsonConvert.DeserializeObject<Libro[]>(response.Content);
foreach (var resultado in resultados)
{
Console.WriteLine(resultado.portada);
}
Console.WriteLine("terminado...");
Console.ReadKey();
}
}
}
на данный момент я не могу изменить поколение json, но я также хочу знать, возможно ли, что json не так
Это JSON
[
{
id: 1,
categoria: "CIENCIA-FICCION",
ruta: "ciencia-ficcion",
estado: 1,
oferta: 0,
precioOferta: 0,
descuentoOferta: 0,
imgOferta: "",
finOferta: "0000-00-00 00:00:00",
fecha: "2020-01-13 14:43:36",
libros: [
{
id: 11,
id_categoria: "6,5,1",
tipo: "",
ruta: "fundamentos",
autor: "J.DM",
estado: 1,
titulo: "fundamentos",
titular: "Titular",
size: 166872,
detalles: "",
precio: 24,
portada: "vistas/img/cabeceras/fundamentos.jpg",
ventas: 0,
oferta: 0,
precioOferta: 0,
entrega: 0,
fecha: "2020-04-01 14:35:59"
}
]
},
{
id: 2,
categoria: "FANTASIA",
ruta: "fantasia",
estado: 1,
oferta: 0,
precioOferta: 0,
descuentoOferta: 0,
imgOferta: "",
finOferta: "0000-00-00 00:00:00",
fecha: "2020-01-13 14:43:58",
libros: [
{
id: 15,
id_categoria: "5,2",
tipo: "",
ruta: "el-principito",
autor: "ANTOINE DE SAINT - EXUPÉRY ",
estado: 1,
titulo: "El principito",
titular: "Titular",
size: 109504,
detalles: "",
precio: 12,
portada: "vistas/img/cabeceras/el-principito.jpg",
ventas: 0,
oferta: 0,
precioOferta: 0,
entrega: 0,
fecha: "2020-03-02 13:57:03"
},
{
id: 16,
id_categoria: "5,2",
tipo: "",
ruta: "el-asno-y-el-caballo",
autor: "CRISTINA RODRÍGUEZ LOMBA",
estado: 1,
titulo: "El asno y el caballo",
titular: "Titular",
size: 8600,
detalles: "",
precio: 0,
portada: "vistas/img/cabeceras/el-asno-y-el-caballo.jpg",
ventas: 0,
oferta: 0,
precioOferta: 0,
entrega: 0,
fecha: "2020-04-01 13:57:03"
}
]
}
]