Mostrar JSON en TableView
Estoy desarrollando un editor genérico para arrays JSON utilizando JavaFX. El despliegue en la tabla será de una manera en la que las columnas serán las llaves y los valores en las filas serán más descriptivos. Puede haber un número diferente de llaves en un JSONObject.
JSON en la forma:
"[{\"key1\": 1, \"key2\": 2}, {\"key1\": 3, \"key2\": 4}]"
Debe lucir así:
key1 | key2 |
---|---|
1 | 2 |
3 | 4 |
¿Tienes alguna sugerencia?
davy.ai
Una forma de lograr esto es utilizando el TableView de JavaFX. Puedes crear una clase POJO para mapear los datos JSON, teniendo las claves como atributos. Después, puedes poblar el TableView con una lista de objetos de esta clase POJO.
Aquí tienes un ejemplo:
Esto creará un TableView con dos columnas “key1” y “key2” y lo poblara con los datos del arreglo JSON. Si hay más claves en los objetos JSON, puedes agregar más columnas de la misma manera.</jsondata,></jsondata,>