网上对JSON for Modern C++ 的使用有一定的介绍,但涉及到jsonArray的时候,就基本找不到多少资料,所以这里的例子,偏重于jsonArray的解析。
- json的解析
例子:解析如下字符串:
{“command”:“start_mission”, “data”:{“waypoints”:[{“latitude”:23.5,“longitude”:45, “altitude”:120},{}]}}
参考代码:
void JsonHelper::get_waypoints(const std::string& message, std::vector<WayPiontData>& waypointList) {
json jobj;
if (json_parse(message, jobj)) {
if (jobj["data"] != nullptr) {
json data = jobj["data"].get<json>();
if (data["waypoints"] != nullptr) {
json waypoints = data["waypoints"].get<json>();
if (waypoints.is_array()) {
int size = waypoints.size();

这篇博客主要探讨了如何使用JSON for Modern C++库处理jsonArray,提供了解析包含数组的JSON字符串以及生成JSON数组的示例代码,强调了C++中与Java不同的处理方式。
最低0.47元/天 解锁文章
1602

被折叠的 条评论
为什么被折叠?



