Json Editor命令行版

Json Editor

  • Json是一种轻量级的数据交换格式,用于表示和存储数据。
  • Json语法简单,便于与程序交互。
  • Json可简单理解为:易于“代码”阅读的文字。
  • RapidJson是一款处理Json的开源库,官网对它的解释如下:

RapidJSON is a JSON parser and generator for C++. It was inspired by RapidXml.

Json编辑器
  • 界面版(QT)的Json编辑器(代码已放出)。其实就是在本文代码底层操作类的基础上,封装了一层QT代码。参考之前的博文:Json编辑器界面版
  • 这里放出程序的源码,欢迎参看。代码地址JsonEditor GitHub
  • 创建Json对象的语法,采用了RapidJson Pointer
  • 由于代码较多,且BZ写得比较简单。因此,这里仅贴出底层操作类的头文件,其余内容自行参看:
#ifndef JSONCOREOPERATION_H
#define JSONCOREOPERATION_H
#ifndef __cplusplus
#   error ERROR:This file requires C++ compliation (use a .cpp suffix)
#endif

#include <string>

#include "rapidjson/document.h"

class HandleJson;

/**
 *JsonCoreOperation
 *
 *define class of JsonCoreOperation
*/
class JsonCoreOperation
{
public:
    JsonCoreOperation() {}
    virtual ~JsonCoreOperation() {}

    bool read(const char* str, const char* indentify, std::string& result);
    bool write(const char* fileName, const char* jsonStr);
    bool parse(const char* jsonStr,HandleJson* handler);
    bool check(const char* jsonStr);
    bool createKey(rapidjson::Document& document, const char* key, const char* value);
    bool createKey(rapidjson::Document& document, const char* key, int value);
    bool queryKey(rapidjson::Document& document, const char* key);
    bool deleteKey(rapidjson::Document& document, const char* key);

private:
    unsigned int errorLineNumber(const char* jsonStr,unsigned int offSet);
    bool checkKey(const char* key);

private:
    enum JSonType
    {
        Type_Null = 0,
        Type_False,
        Type_True,
        Type_Object,
        Type_Array,
        Type_String,
        Type_Number
    };
};

#endif // JSONCOREOPERATION_H
/* EOF */

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

林多

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值