我如何从这里读取JSON数据:http://data.foli.fi/siri/vm,因此它会传回筛选后的数据,如下所示:
[{
"latitude": 60.4827,
"name": "14",
"description": "14: Saramäki -> Erikvalla",
"id": "550018",
"longitude": 22.31275
}, {
"latitude": 60.45902,
"name": "20",
"description": "20: Puutori -> Muhkuri",
"id": "110416",
"longitude": 22.26783
}]
我试过用这样的豆子,但似乎不起作用。
public class ItemsBean{
private double latitude;
@JsonProperty("name")
private String publishedlinename;
@JsonProperty("id")
private String originname;
private String destinationname;
private String vehicleref;
private double longitude;
@JsonIgnore
public String sys;
public int servertime;
public int responsetimestamp;
public String producerref;
public String responsemessageidentifier;
public boolean status;
public boolean moredata;
public int recordedattime;
public int validuntiltime;
public int linkdistance;
public double percentage;
public String lineref;
public String directionref;
public String operatorref;
public String originref;
public String destinationref;
public int originaimeddeparturetime;
public int destinationaimedarrivaltime;
public boolean monitored;
public boolean incongestion;
public boolean inpanic;
public String delay;
public int delaysecs;
public String blockref;
public String next_stoppointref;
public int next_visitnumber;
public String next_stoppointname;
public boolean vehicleatstop;
public String next_destinationdisplay;
public int next_aimedarrivaltime;
public int next_expectedarrivaltime;
public int next_aimeddeparturetime;
public String destinationname_sv;
public String next_stoppointname_sv;
public String __tripref;
public String __routeref;
public String __directionid;
public String originname_sv;
public String next_destinationdisplay_sv;
public ItemsBean(){}
public ItemsBean(double latitude, String publishedlinename, String originname, String destinationname, String vehicleref, double longitude) {
this.latitude = latitude;
this.publishedlinename = publishedlinename;
this.originname = originname;
this.destinationname = destinationname;
this.vehicleref = vehicleref;
this.longitude = longitude;
}
public double getLatitude() {
return latitude;
}
public void setLatitude(double latitude) {
this.latitude = latitude;
}
public String getPublishedlinename() {
return publishedlinename;
}
public void setPublishedlinename(String publishedlinename) {
this.publishedlinename = publishedlinename;
}
public String getOriginname() {
return originname;
}
public void setOriginname(String originname) {
this.originname = originname;
}
public String getNext_destinationdisplay() {
return destinationname;
}
public void setDestinationname(String destinationname) {
this.destinationname = destinationname;
}
public String getVehicleref() {
return vehicleref;
}
public void setVehicleref(String vehicleref) {
this.vehicleref = vehicleref;
}
public double getLongitude() {
return longitude;
}
public void setLongitude(double longitude) {
this.longitude = longitude;
}
@Override
public String toString() {
return "\"" + "[{ " + "latitude: " + latitude + ", " +
"name: " + publishedlinename + ", " +
"description: " + publishedlinename + ": " + originname + " -> " + destinationname + ", " +
"id: " + vehicleref + ", " +
"longitude: " + longitude + " }]" + "\"";
}
}
我尝试过使用读取器,但结果总是null。
2022-08-17 11:43:34,714信息[获取Map数据](版本x工作线程1)空值2022-08-17 11:43:34,715信息[获取Map数据](版本x工作线程1)Map数据:[获取Map数据](版本x工作线程1)[{纬度:0.0,名称:空,说明:空值:空值-〉空值,id:空,经度:0.0元}]
1条答案
按热度按时间mklgxw1f1#
对于过滤,您可以只使用JacksonObjectMapper和JsonNode手动过滤和Map来自json响应的字段到FilteredResult对象列表。
在Camel中可能有更优雅的方法来实现这一点,我也很想知道如何实现。
FileReadUtility只是一个实用程序类,用于从资源文件夹中加载文本文件作为字符串。
Apache Commons IO的Maven依赖性