C++程序、JSON阅读器和摘录

C++ program, JSON reader and extract.

本文关键字:程序 JSON C++      更新时间:2023-10-16

我正在处理一个赋值,它必须读取一个json文件并将其存储在字符串缓冲区数组中。使用structCollection来收集对象、名称和值对。

示例JSON:

0    {
1       "Obj": {
2          "Hello": "working",
3          "Test": "working"
4    }

我可以提取它,并将其存储在结构Collection中。我正在使用:(在循环中)

if(buffer[line_number].find('{')!=string::npos) {

然后使用substr来存储它。

问题是,如果"{"包含在对象或名称值对中,这将不允许。

{
   "Obj": {
      "Hello": "Working {Not working}"
}

数值中的contians。

struct Collection {
   string ObjName;
   string name[50];
   string Value[50]
}

我知道,这个问题很老,但请尝试使用github。有很多很酷的解析器

https://github.com/search?l=C%2B%2B&o=desc&q=json&s=星形&type=存储库&utf8=%E2%9C%93

甚至我的:https://github.com/kurzgame/json-to-map