# include "rapidjson/document.h" # include "rapidjson/writer.h" # include "rapidjson/stringbuffer.h" # include "rapidjson/filewritestream.h" # include "rapidjson/prettywriter.h" # include "rapidjson/filereadstream.h" int main ( int argc , char * * argv ) command_string = "{\"store\":[{\"grid_corners\":[0,1],\"status\":3},{\"grid_corners\":[5,6],\"status\":10}]}" ; char * json = ( char * ) command_string . c_str ( ) ; rapidjson :: Document document ; document . Parse ( json ) ; int store_0_grid_0 = document [ "store" ] [ 0 ] [ "grid_corners" ] [ 0 ] . GetInt ( ) ; int store_0_grid_1 = document [ "store" ] [ 0 ] [ "grid_corners" ] [ 1 ] . GetInt ( ) ; int store_0_status = document [ "store" ] [ 0 ] [ "status" ] . GetInt ( ) ; int store_1_grid_0 = document [ "store" ] [ 1 ] [ "grid_corners" ] [ 0 ] . GetInt ( ) ; int store_1_grid_1 = document [ "store" ] [ 1 ] [ "grid_corners" ] [ 1 ] . GetInt ( ) ; int store_1_status = document [ "store" ] [ 1 ] [ "status" ] . GetInt ( ) ; std :: cout << store_0_grid_0 << std :: endl ; std :: cout << store_0_grid_1 << std :: endl ; std :: cout << store_0_status << std :: endl ; std :: cout << store_1_grid_0 << std :: endl ; std :: cout << store_1_grid_1 << std :: endl ; std :: cout << store_1_status << std :: endl ; return 1 ;

形式2(自由读取大小)

"store":[ [1,2,3] [5,6,7,8,9], [1,2], [2,3]

请对代码自行调整

std::string command_string = "{\"store\":[[0,[1,2,3]],[[5,6,7,8,9],2],[1,2],[2,3]]}" ;
char* json = (char*)command_string.c_str();
rapidjson::Document document;
document.Parse(json);
if (document["store"].IsArray())
   std::cout<<document["store"][0].Size()<<std::endl;
   std::cout<<document["store"][0][1].Size()<<std::endl;
   std::cout<<document["store"][1][0][3].GetInt()<<std::endl;

补充的技巧

可以这么使用

std::string s = "store";
document[s.c_str()].IsArray()
                    描述我们有了一个string类型的字符串,字符串是一个json串,使用C++的rapidjson库解析它代码按照你的需求自行更改代码,我这里只是个例子string内容为{	"store":	[		{			"grid_corners":[0,1],			"status":3		},		{			"grid_corners":[5,6],			"status":10		}	]}#include &lt;iostream&gt;  #include &lt;string.h&
				
C语言使用 JSON一、简介二、使用方法1. 下载引用2. 读取一个文件内容 解析当中的json字符串 CJsonObject 是一个基于cJSON开发的、适用于c++的轻量级的JSON处理器。 开源地址: https://gitee.com/Bwar/CJsonObject.git 二、使用方法 1. 下载引用 从官网下载 源码,引用其中的 CJsonObject.hpp。 #include <string> #include <iostream> #include &
jsoncpp 是一个可以与 JSON 进行交互的C++。官网定义如下: jsoncpp is an implementation of a JSON reader and writer in C++. 通过使用 jsoncpp ,我们可以对 JSON 进行读写。 2 示例代码 2.1 从字符串中... E: Error, pkgProblemResolver::Resolve generated breaks, this may be caused by held packages 29211
E: Error, pkgProblemResolver::Resolve generated breaks, this may be caused by held packages hongdounuoyan: 你机器坏了,我们没坏呀,请移步其它帖子 二维点云ICP原理推导 M.H.T: 请问有没有icp的c++算法实现啊 点云相机手眼标定代码——利用PCL库的ICP算法完成手眼标定 psling12345: 这个方法标出来的误差很大啊 二维点云ICP的C++实现 Young Style: 想问下二维点云icp的速度最快能达到多少? 机械臂手眼标定原理及代码 AL坤哥哥: 博主大大,相机中13组标定板的位姿,x,y,z,rx,ry,rz,,如何获得呢