Hello I`m working at a javafx application and i want to populate a tableview or a listview with my json data:
{
"username" : "Viviana",
"password" : "{��O��s�\u000F�P�g�5\u000B��\u001E'�h\u0004���{��\u001C-����dT*v�\u0007�Ԯ��i�][�.\u0018ʌ�\u001AG��(",
"role" : "client",
"accBalance" : 24.474105780728106",
"email": someone@yahoo.com"
}
From this i want to get just the username and the email to be in my view, can you help me with some ideas because i`m very new at json files, i used jackson and gson to help me with the json files methods. Thank you !
This is my controller code:
public class AdminViewBuyersController{
private ObservableList<User> users = observableArrayList();
@FXML
private TableView<User> table;
@FXML
private TableColumn<Festival, String> user;
@FXML
private TableColumn<Festival, String> email;
private void initialize() throws IOException {
BufferedReader br = null;
try {
br = new BufferedReader(new FileReader(new File("C:\\Users\\vladd\\.registration-example\\config")));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
if (br != null) {
String st;
while ((st = br.readLine()) != null) {
addUsersToList(new GsonBuilder().create().fromJson(st, User.class));
}
}
setTable();
}
private void addUsersToList(User user) {
users.add(user);
}
private void setTable() {
user.setCellValueFactory(new PropertyValueFactory<>("userName"));
email.setCellValueFactory(new PropertyValueFactory<>("email"));
table.setItems(users);
}