![](/img/trans.png)
[英]How to convert 2 Java String arrays of keys & values into a json object
[英]Convert JSON file with arrays to Java object
如何使用许多Arraysinside转换JSON形式? 那看起来是我的JSON的一部分:
"features": [
{
"geometry": {
"coordinates": [
16.91828856,
52.3838415
],
"type": "Point"
},
"id": "ROLN04",
"type": "Feature",
"properties": {
"zone": "A",
"route_type": "3",
"headsigns": "238",
"stop_name": "Rolna"
}
},
{
"geometry": {
"coordinates": [
16.88799654,
52.40252503
],
"type": "Point"
},
"id": "RJNJ01",
"type": "Feature",
"properties": {
"zone": "A",
"route_type": "3",
"headsigns": "251",
"stop_name": "Rondo Jana Nowaka-JezioraĹskiego"
}
},
我使用对象停止,坐标,名称停止和总线(在JSON中为“标题”)的数组:
private Double coordinateY;
private Double coordinateX;
private String nameStop;
private String withLine; ("headsigns" in 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...
}
使用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;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.