我有一个JSON文件,其中嵌套了geoJSON功能集。
是否可以使用type myStruct struct {
Key string `json:"key"`
Value string `json:"value"`
}
key, value := gen()
data := myStruct{Key: key, Value: value}
myJSON, err := json.Marshal(data)
err = conn.WriteMessage(websocket.TextMessage, myJSON)
读取JSON文件,提取geoJSON位,然后将结果jsonlite::read_json()
转换为list
对象?另一种方法是使用sf
之类的包将list
写回JSON(文本)并读取geoJSON。
这是我的JSON代码如下:
geojsonio
答案 0 :(得分:1)
也许
x <- '{
"all": [
{
"type": "Feature",
"geometry": {
"type": "GeometryCollection",
"geometries": [
{
"type": "Point",
"coordinates": [
-75.155727,
39.956318
]
},{
"type": "LineString",
"coordinates": [
[
-75.15567895337301,
39.95653558798881
],[
-75.15575995337292,
39.95616931624319
]
]
},{
"type": "Point",
"coordinates": [
-75.15566,
39.956432
]
}
]
},
"properties": null
}
]
}'
sf::st_read(jqr::jq(x, ".all[]"))
(将字符串编辑为有效的JSON)