Closed bluelancer closed 6 years ago
If you have any way to change the JSON that is coming to you, I would recommend making it so that it sends a list of boards, and the boards have a "name" property in which you can put "Board 1_1" or "Board 1_0". That will make it so that you can be more dynamic. The problem you are running into is that you have a property name that can be dynamic. That's why I propose what I said before. If you must deal with that JSON that way you can do the following:
@JsonObject
public class Boards {
@JsonField(name = "objects")
List<BoardContainer> boardContainers;
public List<BoardContainer> getBoardContainers() {
return boardContainers;
}
public void setBoardContainers(List<BoardContainer> boardContainers) {
this.boardContainers = boardContainers;
}
}
@JsonObject
public class BoardContainer {
@JsonField(name = "Board 1_0")
private Board board_1_0;
@JsonField(name = "Board 1_1")
private Board board_1_1;
public Board getBoard_1_0() {
return board_1_0;
}
public void setBoard_1_0(Board board_1_0) {
this.board_1_0 = board_1_0;
}
public Board getBoard_1_1() {
return board_1_1;
}
public void setBoard_1_1(Board board_1_1) {
this.board_1_1 = board_1_1;
}
}
@JsonObject
public class Board {
@JsonField
private String detectionPercentage;
@JsonField
private String top;
@JsonField
private String bottom;
@JsonField
private String left;
@JsonField
private String right;
public String getDetectionPercentage() {
return detectionPercentage;
}
public void setDetectionPercentage(String detectionPercentage) {
this.detectionPercentage = detectionPercentage;
}
public String getTop() {
return top;
}
public void setTop(String top) {
this.top = top;
}
public String getBottom() {
return bottom;
}
public void setBottom(String bottom) {
this.bottom = bottom;
}
public String getLeft() {
return left;
}
public void setLeft(String left) {
this.left = left;
}
public String getRight() {
return right;
}
public void setRight(String right) {
this.right = right;
}
}
ThX!
Dear all,
I have a JSON looks like:
As objects in an array. I tried
and tried to grab
detectionPercentage
, yet it is not working, what is wrong?