我想将传单的字符串 json 转换为 geojson,这是我的 json
[
{
"longitude": "xxx",
"latitude": "xxx",
"kode_toko": "xxx",
"nama_toko": "xxx",
"postal_code": xxx
},
等(我的json中有更多类似的内容)..
这是我将数据从数据库转换为 json 字符串的代码
List<Object> data = new ArrayList<>();
Items item = null;
while(rs.next()) {
item = new Items("","","","",0);
//json = rs.getString("t");
item.latitude = rs.getString("latitude");
item.longitude = rs.getString("longitude");
item.code = rs.getString("code");
item.name = rs.getString("name");
item.postalcode = rs.getInt("postal_code");
data.add(item);
//System.out.println("Items: " +data);
//System.out.println("Item " +item);
}
//convert to json
GsonBuilder build = new GsonBuilder();
build.setPrettyPrinting();
Gson gson = build.create();
String json = gson.toJson(data); //convert ke string`
如何将这个json字符串数据转换为geojson数据? 先谢谢了
最佳答案
GeoJSON 是 JSON,因此无需构建从数据发布的 JSON,只需构建最终的 GeoJSON,
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [xxx, yyy]
},
"properties": {
"kode_toko": "www",
"nama_toko": "uuu",
"postal_code": "vvv"
}
}
顺便说一句,在坐标
中,xxx是经度,yyy是纬度。
关于java - 使用java将java字符串转换为geojson,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60331833/