FTP | CCD | Buscar | Trucos | Trabajo | Foros |
|
Registrarse | FAQ | Miembros | Calendario | Guía de estilo | Temas de Hoy |
|
Herramientas | Buscar en Tema | Desplegado |
#1
|
||||
|
||||
Obtener campo usando REST
Usando los componentes de REST y JSON en Delphi 10, ¿como puedo mostrar los datos en Label?
Ejemplo: Cita:
Y como segunda pregunta, ¿Como puedo mostrar estos valores en una StringGrid y no en una DBGrid?. De antemano, gracias. Cita:
|
#2
|
||||
|
||||
¿Has visto el ejemplo de la web de embarcadero?
Puedes usar Live Bindings o directamente leer de un objeto TJSONObject usando el metodo GetValue. Ejemplo
__________________
Mallenat |
#3
|
||||
|
||||
Si vas a trabajar mucho con estar estructura (y también para mantener un código limpio), vale la pena utilizar esta herramienta de la que ya he hablado en el blog.
JsonToDelphiClass Permite como su nombre indica, generar una unit con las clases necesarias para trabajar con el JSON que le proporciones. Si la generas para este JSON obtendrás el fichero que te adjunto. La gracias es que con una línea como esta puedes cargar todo el JSON es un objeto.
A partir de este punto, en ULista tienes todo el JSON. Para recorrerlo y acceder a los elementos puedes utilizar algo así (o para guardarlos en un TSTringGrid):
__________________
Germán Estévez => Web/Blog Guía de estilo, Guía alternativa Utiliza TAG's en tus mensajes. Contactar con el Clubdelphi P.D: Más tiempo dedicado a la pregunta=Mejores respuestas. Última edición por Neftali [Germán.Estévez] fecha: 07-10-2017 a las 12:57:30. Razón: Añadr adjunto |
#4
|
||||
|
||||
Neftali, maravilloso el JsonToDelphiClass. Hasta tiene una versión online https://jsontodelphi.com Me facilito la vida.
Aprendiendo este submundo. Gracias |
#5
|
||||
|
||||
Hola neftali .. muchas gracias por compartir ese codigo y el sitio para crear esas clases. Es fantastico.
Ahora te pido una ayuda para comprender como "leer" los objetos de dicha clase con este Json [ { "id": 71, "companyId": 4, "name": "Leo b", "email": null, "takeAway": false, "deviceId": 457, "state": "NEW", "dateNew": 1533517288534, "street": "Mac eachen", "total": 332, "number": "1324", "betweenStreet": "", "apartmentNumber": "", "telephone": "099127695", "annotation": null, "products": [ { "comment": null, "code": 709, "amount": 2, "name": "PIZZETA A LA SALSA", "total": 185, "productItemsName": [] } ], "dateInitProcess": null, "timeToFinishProcess": null, "dateFinish": null, "dateCancel": null, "cancelBecause": null }, { "id": 70, "companyId": 4, "name": "Leo b", "email": null, "takeAway": false, "deviceId": 457, "state": "NEW", "dateNew": 1533517256850, "street": "Mac eachen", "total": 170, "number": "1324", "betweenStreet": "", "apartmentNumber": "", "telephone": "099127695", "annotation": null, "products": [ { "comment": null, "code": 102, "amount": 1, "name": "PIZZA", "total": 75, "productItemsName": [] }, { "comment": null, "code": 101, "amount": 1, "name": "MUZZARELLA", "total": 115, "productItemsName": [] } ], "dateInitProcess": null, "timeToFinishProcess": null, "dateFinish": null, "dateCancel": null, "cancelBecause": null }, ] Me ha definido esta clase pero no me doy cuenta como utilizarla. Muchas gracias desde ya !!!!
|
#6
|
||||
|
||||
Hola foristas..
Alguien que me ayude a entender como interpretar esa clase para poder obtener datos del json que menciono ?? Muchas gracias !! |
#7
|
||||
|
||||
Hola.. alguien que me ayude con esta clase ?? No se como implementarla y llamarla..
Muchas gracias !!! |
#8
|
||||
|
||||
Hola.
Revisa que el JSON que has colocado esté bien (si hace falta utiliza etiquetes para que la web no elimine caracteres). Tal y como está no me deja generar la clase. Para utilizarla, puedes usar un código similar a este. Siempre se empieza utilizando la función FromJsonString. En tu caso la de la clase TProductsClass.
__________________
Germán Estévez => Web/Blog Guía de estilo, Guía alternativa Utiliza TAG's en tus mensajes. Contactar con el Clubdelphi P.D: Más tiempo dedicado a la pregunta=Mejores respuestas. |
#9
|
||||
|
||||
Gracias German, hace dias que estoy tratando de "interpretar" el json con esa clase, pero mis conocimientos de clases son minimos..
el json que deseo analizar es este..
He testeado este json en la pagina de jsontodelphi y me genera la clase, mi problema es que no se luego como utilizarla. Ademas he mirado el post que mencionas, pero no le he comprendido del todo. .. Mil gracias por tu invalorable ayuda.. |
|
|
Temas Similares | ||||
Tema | Autor | Foro | Respuestas | Último mensaje |
Como obtener datos de un servidor rest con autenticacion | lbidi | Varios | 2 | 20-03-2017 15:41:38 |
PayPal usando REST | oesqueda | Delphi para la web | 5 | 02-12-2014 00:36:41 |
Insertar *.JPG en campo blob usando IBX | servicomp | Firebird e Interbase | 2 | 22-10-2010 03:27:56 |
consulta SQL en Delphi 5 usando like en un campo memo | MaSSaKKre | SQL | 4 | 12-02-2007 01:52:02 |
|