如何使用许多Arraysinside转换表单JSON? 那怎么看我的JSON的一部分:
private Double coordinateY;
private Double coordinateX;
private String nameStop;
private String withLine; ("headsigns" in JSON)
我的数据是带有对象停止的数据,带坐标,名称为Stop,以及总线(在JSON中是“标题”):
@Autowired
JSON json;
@Autowired
Stop stop;
JSONParser parser = new JSONParser();
List<String> coordinates;
List<Stop> allStopList = new ArrayList<>();
public List<Stop> convert() {
try {
Object obj = parser
.parse(new BufferedReader(new InputStreamReader(getClass().getResourceAsStream("poznanS.json"))));
JSONObject jsonObject = (JSONObject) obj;
JSONArray stopArray = (JSONArray) jsonObject.get("features");
for (Iterator stopIndex = stopArray.iterator(); stopIndex.hasNext();) {
JSONObject stopJSONObject = (JSONObject) stopIndex.next();
JSONArray coordynateArray = (JSONArray) stopJSONObject.get("geometry");
stop.setCoordinateY...
stop.setCoordinateX...
stop.setNameStop...
stop.setWithLine...
}
我的课我看起来像那样:
{
"test": {
"parts": [
{
"partgroup": "1",
"screens": [
{
"questions": [
{
"questionno": 1
}
]
}
]
}
]
}
}
答案 0 :(得分:0)
使用javax.ws.rs.core.GenericType
例如:
protected List<TypeList> getTypesOfGroup(String group) {
WebTarget target = restClient.getWebTargetByPath("typelist/groups").path(group);
List<TypeList> types = target.request(RestClient.APPLICATION_JSON)
.get(new GenericType<List<TypeList>>() {
});
return types;
}