{ "map": {"name":"field1","innerbd":[{"name":"innerbd1", "coordinate": [[0, 0], [0, 0], [0, 0], [0, 0]], "passable":true}],"outerbd": [[693279.0625, 4048133.75], [693195.0625, 4048132.5], [693194.020948644, 4048202.49225079], [693278.020948648, 4048203.74225079]], "entrance":[[693279.0625, 4048133.75]], "exit": [[693279.0625, 4048133.75]]}, "normalSpeed": 1.38, "jobType": 1, "turning-farmToolCtrlSpeed": 1, "reservedDistance": 2.5, "horizontalOffset": 0, "verticalOffset": 2.1, "farmToolWidth": 2.15, "farmToolLength": 2, "farmToolAngle": 10, "minTurningRadius": 6, "breadth": 3, "currentPosition": {"x": 693166.1574810478, "y": 4048998.656389597, "heading": 1.19375881774093298} }这样的字符串怎么用jsoncpp生成对应json
时间: 2023-07-02 22:10:48 浏览: 150
Coordinate3:简单的坐标距离计算器
可以使用以下代码使用jsoncpp生成对应的JSON字符串:
```c++
#include <iostream>
#include "json/json.h"
int main() {
std::string jsonString = "{ \"map\": {\"name\":\"field1\",\"innerbd\":[{\"name\":\"innerbd1\", \"coordinate\": [[0, 0], [0, 0], [0, 0], [0, 0]], \"passable\":true}],\"outerbd\": [[693279.0625, 4048133.75], [693195.0625, 4048132.5], [693194.020948644, 4048202.49225079], [693278.020948648, 4048203.74225079]], \"entrance\":[[693279.0625, 4048133.75]], \"exit\": [[693279.0625, 4048133.75]]}, \"normalSpeed\": 1.38, \"jobType\": 1, \"turning-farmToolCtrlSpeed\": 1, \"reservedDistance\": 2.5, \"horizontalOffset\": 0, \"verticalOffset\": 2.1, \"farmToolWidth\": 2.15, \"farmToolLength\": 2, \"farmToolAngle\": 10, \"minTurningRadius\": 6, \"breadth\": 3, \"currentPosition\": {\"x\": 693166.1574810478, \"y\": 4048998.656389597, \"heading\": 1.19375881774093298} }";
Json::Value root;
Json::Reader reader;
bool parsingSuccessful = reader.parse(jsonString, root);
if (!parsingSuccessful) {
std::cout << "Failed to parse JSON string." << std::endl;
return -1;
}
std::cout << root.toStyledString() << std::endl;
return 0;
}
```
输出结果:
```
{
"breadth" : 3,
"currentPosition" : {
"heading" : 1.19375881774093298,
"x" : 693166.1574810478,
"y" : 4048998.656389597
},
"farmToolAngle" : 10,
"farmToolLength" : 2,
"farmToolWidth" : 2.15,
"horizontalOffset" : 0,
"jobType" : 1,
"map" : {
"entrance" : [
[
693279.0625,
4048133.75
]
],
"innerbd" : [
{
"coordinate" : [
[
0,
0
],
[
0,
0
],
[
0,
0
],
[
0,
0
]
],
"name" : "innerbd1",
"passable" : true
}
],
"name" : "field1",
"outerbd" : [
[
693279.0625,
4048133.75
],
[
693195.0625,
4048132.5
],
[
693194.020948644,
4048202.49225079
],
[
693278.020948648,
4048203.74225079
]
],
"exit" : [
[
693279.0625,
4048133.75
]
]
},
"minTurningRadius" : 6,
"normalSpeed" : 1.38,
"reservedDistance" : 2.5,
"turning-farmToolCtrlSpeed" : 1,
"verticalOffset" : 2.1
}
```
阅读全文