C++ Json解析CJsonObject的详细使用

本文详细介绍了如何在C++中使用CJsonObject库进行Json解析。通过引用头文件,修改特定数据结构,结合官方案例,提供了一个完整的使用流程。读者可以下载完整案例进行实践。
摘要由CSDN通过智能技术生成

引用头文件:

#include <string>
#include <iostream>
#include <fstream>
#include <cassert>
#include <stdio.h>
#include <io.h>
#include<sstream>
#include <vector>
#include "CJsonObject.hpp"

    using namespace std;
    using namespace neb;
  	CJsonObject Objson;

 

1 __declspec(dllexport)  void  __stdcall read_JSon(char* path)
2 {
3     ifstream t(path);
4     string str((istreambuf_iterator<char>(t)),istreambuf_iterator<char>());
5     string strValue;
6     Objson= CJsonObject(str);
7     cout << "-------------------------------------------------------------------" << std::endl;}
加载JSON文件
 1     //保存JSON文件
 2 __declspec(dllexport)  void  __stdcall  write_string_to_file_append(char*  file_string)
 3 {
 4     /*remove(file_string);*/
 5     std::ofstream    OsWrite(file_string, std::ofstream::trunc);
 6     OsWrite << Objson.ToString();
 7     OsWrite << std::endl;
 8     OsWrite.close();
 9     std::cout << "------------------执行完毕------------------------" << std::endl;
10 }
保存修改后的JSON结构

1.修改如下图数据结构:

 1 __declspec(dllexport)  void  __stdcall FxmWindDirectBaseLine(int num,  int count, char** pArr, int* sArr, int* iArr)
 2 {
 3 
 4     string iValue;
 5     for (int i = 0; i < Objson["WindDirectLine"]["coordinates"][num]["mWindDirectBaseLine"].GetArraySize(); i++)
 6     {
 7         Objson["WindDirectLine"]["coordinates"][num]["mWindDirectBaseLine"].Delete(i);
 8         i--;
 9     }
10     cout << "---------------" << endl;
11     cout << Objson["WindDirectLine"]["coordinates"][num]["mWindDirectBaseLine"].GetArraySize() << endl;
12     CJsonObject je;
13     
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值