Git Product home page Git Product logo

cjsonobject's Introduction

English | 中文

Author License


CJsonObject is a newly developed C++ version based on an older version of cJSON. The biggest advantage of CJsonObject is that it is light, simple and easy to use, and the development efficiency is very high. CJsonObject is much simpler and easier to use than cJSON.

Bwar's first use of cJSON was the development of a mobile push project in 2013. At that time, although cJSON was useful, but it was easy to forget about free the memory allocated by cJSON. In 2014, Bwar use cJSON again when developing another project. In order to improve the ease of use of cJSON and improve the development efficiency, cJSON was encapsulated and 64-bit integers were supported. In the development of CJsonObject, cJSON was modified slightly.

CJsonObject has verified its stability in several successful case for 5 years. At the same time, CJsonObject integrated into Nebula and was widely used.

Here is a wiki FAQ in chinese.

cjsonobject's People

Contributors

alvarez86 avatar anton-sergeev avatar blattms avatar bwar avatar casperinous avatar cherima007 avatar chisholmkyle avatar davegamble avatar deborag avatar dongwenhuang avatar ffontaine avatar fsmaxb avatar gagath avatar gatzka avatar hao-lion-zju avatar kbranigan avatar kekxv avatar macrogu avatar mjerris avatar pawelwms avatar prefetchnta avatar rdleal avatar rmeertens avatar rvagg avatar schmidtw avatar simon-p-r avatar yangfl avatar yoyoyoyoga-seu avatar zhaosj1991 avatar zhaozhixu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cjsonobject's Issues

please add tag before version with sstream

could you please add a release tag before the version that uses sstream? That version looks usable with microcontrollers, but adding sstream is pulling in too much stuff from c++ streams including exceptions, and that is increasing program size too much.

prase_number

解析这个字串时:1283949231388184576
返回:1283949231388184320

CJsonObject::operator[] vs2019 c++14 release have exception

when such code like :
std::string=ojson[xxx1][xxx2][xxx3][xxx](0);
it works on debug mode,
but under release mode,evenwith disable optimize,it was crashed;
maybe the reason is "m_array_iter" uninitialized.

            just modify operator[] function:
	//if (uiWhich == m_uiLastArrayIndex && m_array_iter != m_mapJsonArrayRef.end())
	//{
	//	return(*(m_array_iter->second));
	//}

all things will be fine.

负整数问题,修复不完全,double,float读取还是有问题

感谢bwarliao提供了这么好的封装,在应用过程中遇到的问题,自己微调了下,看能不能采纳。
注意到对出现的负整数问题进行了修复(转换字符串时加了“.”,Get系列方法修改),如果mqtt消息通信双方都用本库没问题,但和第3方交互时,可能会遇到没有“.”的情况。
在else if (pJsonStruct->type == cJSON_Int)强制转换类型段微调下可以解决问题:
bool CJsonObject::Get(int iWhich, double& dValue) const
{
。。。。。。。。
if (pJsonStruct->type == cJSON_Double)
{
dValue = pJsonStruct->valuedouble;
return(true);
}
else if (pJsonStruct->type == cJSON_Int)
{
dValue = (int64)(pJsonStruct->valueint);
return(true);
}
return(false);
}
原代码 dValue = (double)(pJsonStruct->valueint);
导致读取错误,float的也是同样问题,需要使用(int32)转换。
getfloat,getdouble系列4个函数if (pJsonStruct->type == cJSON_Int)段需要调整;

无法解析的外部符号

这个库需要在项目中编译,否则只放在项目目录中引用而不编译,可能会出现编译方式不一样(或其他原因)而导致这个问题。

IsEmpty方法感觉语义不清

对于一个没有子节点的CJsonObject,调用这个方法会返回false;
当这个空的CJsonObject调用了Clear之后,再调用IsEmpty又会返回true;
IsEmpty这个方法是用来判断某个节点是空节点的吗?还是用来判断某个节点是否存在的?那么跟IsKeyExist有什么区别呢?

有关CJsonObject []和=重载符的疑问

`
#include

#include "json/CJsonObject.hpp"

using namespace std;
using namespace neb;

int main()
{
/*
{
"test": {
"test2": 1
}
}
*/
std::string data = "{"test":{"test2":1}}";
cout << data << endl;

CJsonObject a, b, c;
a.Parse(data);
b = a;

int t = -1;
a["test"].Get("test2", t);
cout << "t: " << t << endl;

b["test"].Replace("test2", 2);
b["test"].Get("test2", t);
cout << "t: " << t << endl;

a = b;
a["test"].Get("test2", t);
cout << "t: " << t << endl;

a.Get("test", c);
c.Get("test2", t);
cout << "t: " << t << endl;


system("pause");
return 0;

}
`
image

第三个结果 期望是 2 吧,等于操作的时候是不是也需要清空map
[]里的map是为了性能上的优化吗

建议

建议增加三个接口,方便直接使用:json["title"].toString() // 直接得到标题

std::string toString() const;
uint64 toNumber() const;
double toDouble() const;


	std::string CJsonObject::toString() const
	{
		if (m_pJsonData != NULL && m_pJsonData->type == cJSON_String)
		{
			return m_pJsonData->valuestring;
		}
		else if (m_pExternJsonDataRef != NULL && m_pExternJsonDataRef->type == cJSON_String)
		{
			return m_pExternJsonDataRef->valuestring;
		}
		return "";
	}
	uint64 CJsonObject::toNumber() const
	{
		if (m_pJsonData != NULL && m_pJsonData->type == cJSON_Int)
		{
			return m_pJsonData->valueint;
		}
		else if (m_pExternJsonDataRef != NULL && m_pExternJsonDataRef->type == cJSON_Int)
		{
			return m_pExternJsonDataRef->valueint;
		}
		return false;
	}
	double CJsonObject::toDouble() const
	{
		if (m_pJsonData != NULL && (m_pJsonData->type == cJSON_Double || m_pJsonData->type == cJSON_Int))
		{
			return m_pJsonData->valuedouble;
		}
		else if (m_pExternJsonDataRef != NULL && (m_pExternJsonDataRef->type == cJSON_Double || m_pExternJsonDataRef->type == cJSON_Int))
		{
			return m_pExternJsonDataRef->valuedouble;
		}
		return false;
	}

compile error

提示‘cJSON_CreateNumber’ was not declared in this scope
#define cJSON_AddNumberToObject(object,name,n) cJSON_AddItemToObject(object, name, cJSON_CreateNumber(n))

你这个版本代码里面确实没有cJSON_CreateNumber函数
^

uint64的处理问题

输入(Add):"userid":4796440449449984
输出(ToString):"userid":1361903616

修改函数:static char *print_int(cJSON *item)中
sprintf(str, "%lu", item->valueint); 改为 sprintf(str, "%llu", item->valueint);

请检查是否正确?还有2个地方是否需要修改?

Android上使用,MAC编译。
Thanks!

关于IsNull方法

{“key":"value"}
我的理解是IsNull("key")返回true说明key不存在
但是程序运行结果不太对

多线程解析错误json字符串问题——by aiyomajun

这个封装确实不错,但是我在使用这个库的时候遇到了一些问题:
1.小数点最多只能有6位,位数不能自由控制,这个问题影响不大
2.在多线程中使用会有问题,特别是,多个不同的线程同时Parse 多个非json格式的字符串时,全局的error指针会被另一个线程改写,然后另一个线程快速释放了这部分内存,导致这个指针指向的区域无效,从而发生段错误

无法解析的外部符号

软件 :QT 5.14 VS2019 CMake 3.16 C++11
前提:
vs2019 新建空项目,添加cJSON.h cJSON.c CJsonObject.hpp CJsonObject.cpp到空项目,debug release demo编译运行正常;
问题:
QT创建项目,CMake配置添加cJSON.h cJSON.c CJsonObject.hpp CJsonObject.cpp到项目中 ,vs2019打开该项目,debug release模式编译 : 无法解析的外部符号;

set(ProjectName mainwindow)
project(${ProjectName} LANGUAGES CXX)
cmake_minimum_required(VERSION 3.3 FATAL_ERROR)
set (CMAKE_CXX_STANDARD 11)

#添加预编译宏
ADD_DEFINITIONS(-DTORRENT_LIBRARY)
ADD_DEFINITIONS(-DNO_FREETYPE)
ADD_DEFINITIONS(-DUNICODE -D_UNICODE)
ADD_DEFINITIONS(-DHCPP_LEGACY_API)


#设置自动生成moc文件,一定要设置
set(CMAKE_AUTOMOC ON) # For meta object compiler
set(CMAKE_AUTORCC ON) # Resource files
set(CMAKE_AUTOUIC ON) # UI files

#指定Qt路径和启用当前目录(按需设置)
#set(CMAKE_PREFIX_PATH "C:/Qt/Qt5.14.2/5.14.2/msvc2017_64/lib/cmake")
list(APPEND CMAKE_PREFIX_PATH "C:/Qt/Qt5.14.2/5.14.2/msvc2017_64/lib/cmake")
set(CMAKE_INCLUDE_CURRENT_DIR ON)

# 引入Qt库
find_package(Qt5Widgets REQUIRED)
find_package(Qt5Gui REQUIRED)
find_package(Qt5Core REQUIRED)
find_package(Qt5Network REQUIRED)
find_package(Qt5Concurrent REQUIRED)
					
Set(Project_Headers ${PROJECT_SOURCE_DIR}/mainwindow.h
					${PROJECT_SOURCE_DIR}/cJSON.h 
					${PROJECT_SOURCE_DIR}/CJsonObject.hpp)
		  
Set(Project_Sources ${PROJECT_SOURCE_DIR}/main.cpp
					${PROJECT_SOURCE_DIR}/mainwindow.cpp
					${PROJECT_SOURCE_DIR}/cJSON.c
					${PROJECT_SOURCE_DIR}/CJsonObject.cpp)
				  
Set(Project_Sources ${Project_Sources})
Set(Project_Headers ${Project_Headers})
Set(Project_UIs ${PROJECT_SOURCE_DIR}/${ProjectName}.ui)


#创建工程文件
add_executable(${PROJECT_NAME} ${Project_Sources} ${Project_Headers} ${Project_UIs})
#添加依赖项
target_link_libraries(${PROJECT_NAME}  Qt5::Widgets Qt5::Network)
1>CJsonObject.obj : error LNK2019: 无法解析的外部符号 cJSON_Parse,该符号在函数 "public: bool __cdecl neb::CJsonObject::Parse(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (?Parse@CJsonObject@neb@@QEAA_NAEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) 中被引用
1>CJsonObject.obj : error LNK2019: 无法解析的外部符号 cJSON_Print,该符号在函数 "public: class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl neb::CJsonObject::ToFormattedString(void)const " (?ToFormattedString@CJsonObject@neb@@QEBA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ) 中被引用
1>CJsonObject.obj : error LNK2019: 无法解析的外部符号 cJSON_PrintUnformatted,该符号在函数 "public: class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl neb::CJsonObject::ToString(void)const " (?ToString@CJsonObject@neb@@QEBA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ) 中被引用
1>CJsonObject.obj : error LNK2019: 无法解析的外部符号 cJSON_Delete,该符号在函数 "public: void __cdecl neb::CJsonObject::Clear(void)" (?Clear@CJsonObject@neb@@QEAAXXZ) 中被引用
1>CJsonObject.obj : error LNK2019: 无法解析的外部符号 cJSON_GetArraySize,该符号在函数 "public: int __cdecl neb::CJsonObject::GetArraySize(void)" (?GetArraySize@CJsonObject@neb@@QEAAHXZ) 中被引用
1>CJsonObject.obj : error LNK2019: 无法解析的外部符号 cJSON_GetArrayItem,该符号在函数 "public: class neb::CJsonObject & __cdecl neb::CJsonObject::operator[](unsigned int)" (??ACJsonObject@neb@@QEAAAEAV01@I@Z) 中被引用
1>CJsonObject.obj : error LNK2019: 无法解析的外部符号 cJSON_GetObjectItem,该符号在函数 "public: bool __cdecl neb::CJsonObject::AddEmptySubObject(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (?AddEmptySubObject@CJsonObject@neb@@QEAA_NAEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) 中被引用
1>CJsonObject.obj : error LNK2019: 无法解析的外部符号 cJSON_CreateNull,该符号在函数 "public: bool __cdecl neb::CJsonObject::AddNull(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (?AddNull@CJsonObject@neb@@QEAA_NAEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) 中被引用
1>CJsonObject.obj : error LNK2019: 无法解析的外部符号 cJSON_CreateBool,该符号在函数 "public: bool __cdecl neb::CJsonObject::Add(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,bool,bool)" (?Add@CJsonObject@neb@@QEAA_NAEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@_N1@Z) 中被引用
1>CJsonObject.obj : error LNK2019: 无法解析的外部符号 cJSON_CreateDouble,该符号在函数 "public: bool __cdecl neb::CJsonObject::Add(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,float)" (?Add@CJsonObject@neb@@QEAA_NAEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@M@Z) 中被引用
1>CJsonObject.obj : error LNK2019: 无法解析的外部符号 cJSON_CreateInt,该符号在函数 "public: bool __cdecl neb::CJsonObject::Add(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,int)" (?Add@CJsonObject@neb@@QEAA_NAEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@H@Z) 中被引用
1>CJsonObject.obj : error LNK2019: 无法解析的外部符号 cJSON_CreateString,该符号在函数 "public: bool __cdecl neb::CJsonObject::Add(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (?Add@CJsonObject@neb@@QEAA_NAEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@0@Z) 中被引用
1>CJsonObject.obj : error LNK2019: 无法解析的外部符号 cJSON_CreateArray,该符号在函数 "public: bool __cdecl neb::CJsonObject::AddEmptySubArray(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (?AddEmptySubArray@CJsonObject@neb@@QEAA_NAEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) 中被引用
1>CJsonObject.obj : error LNK2019: 无法解析的外部符号 cJSON_CreateObject,该符号在函数 "public: bool __cdecl neb::CJsonObject::AddEmptySubObject(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (?AddEmptySubObject@CJsonObject@neb@@QEAA_NAEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) 中被引用
1>CJsonObject.obj : error LNK2019: 无法解析的外部符号 cJSON_AddItemToArray,该符号在函数 "public: bool __cdecl neb::CJsonObject::Add(class neb::CJsonObject const &)" (?Add@CJsonObject@neb@@QEAA_NAEBV12@@Z) 中被引用
1>CJsonObject.obj : error LNK2019: 无法解析的外部符号 cJSON_AddItemToArrayHead,该符号在函数 "public: bool __cdecl neb::CJsonObject::AddAsFirst(class neb::CJsonObject const &)" (?AddAsFirst@CJsonObject@neb@@QEAA_NAEBV12@@Z) 中被引用
1>CJsonObject.obj : error LNK2019: 无法解析的外部符号 cJSON_AddItemToObject,该符号在函数 "public: bool __cdecl neb::CJsonObject::AddEmptySubObject(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (?AddEmptySubObject@CJsonObject@neb@@QEAA_NAEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) 中被引用
1>CJsonObject.obj : error LNK2019: 无法解析的外部符号 cJSON_DeleteItemFromArray,该符号在函数 "public: bool __cdecl neb::CJsonObject::Delete(int)" (?Delete@CJsonObject@neb@@QEAA_NH@Z) 中被引用
1>CJsonObject.obj : error LNK2019: 无法解析的外部符号 cJSON_DeleteItemFromObject,该符号在函数 "public: bool __cdecl neb::CJsonObject::Delete(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (?Delete@CJsonObject@neb@@QEAA_NAEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) 中被引用
1>CJsonObject.obj : error LNK2019: 无法解析的外部符号 cJSON_ReplaceItemInArray,该符号在函数 "public: bool __cdecl neb::CJsonObject::Replace(int,class neb::CJsonObject const &)" (?Replace@CJsonObject@neb@@QEAA_NHAEBV12@@Z) 中被引用
1>CJsonObject.obj : error LNK2019: 无法解析的外部符号 cJSON_ReplaceItemInObject,该符号在函数 "public: bool __cdecl neb::CJsonObject::Replace(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class neb::CJsonObject const &)" (?Replace@CJsonObject@neb@@QEAA_NAEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@AEBV12@@Z) 中被引用
1>D:\workSpace\Qt\untitled\build\Debug\mainwindow.exe : fatal error LNK1120: 21 个无法解析的外部命令

建议用标准的整数类型代替

比如,这些都不好
#if __WORDSIZE == 64
typedef long int64;
typedef unsigned long uint64;
#else
typedef int_fast64_t int64;
typedef uint_fast64_t uint64;
#endif
#else
typedef long long int64;

都不是标准的,没有可移植性啊;
建议都用 stdint.h里面的标准类型代替:
比如 int64_t
uint64_t
int32_t
uint32_t

等等

AddSubObject和AddSubArray

相对已有API AddEmptySubObject和AddSubArray,
希望能增加AddSubObject和AddSubArray,允许将构造好的JsonObject或JsonArray加入进来。

之前看的不仔细,有一个Add函数是解决这个问题的,抱歉。

android 编译64位报错

darwin-x86_64/lib/gcc/aarch64-linux-android/4.9.x/../../../../aarch64-linux-android/bin/ld: CMakeFiles/jniUtil.dir/src/main/jni/CJsonObject.cpp.o: relocation R_AARCH64_MOVW_UABS_G0_NC against `a local symbol' can not be used when making a shared object; recompile with -fPIC
CMakeFiles/jniUtil.dir/src/main/jni/CJsonObject.cpp.o: error adding symbols: Bad value
clang++: error: linker command failed with exit code 1 (use -v to see invocation)

一个下标问题!

{
"request_id": "4e902ed42eb011edb979179a63eecfae",
"code": 0,
"msg": "",
"data": {
"fields": [
"is_open"
],
"items": [
[
1
]
],
"has_more": false
}
}
当要获取items 的值时候:
const char* data = "{\r\n "request_id": "4e902ed42eb011edb979179a63eecfae",\r\n "code": 0,\r\n "msg": "",\r\n "data": {\r\n "fields": [\r\n "is_open"\r\n ],\r\n "items": [\r\n [\r\n 99\r\n ]\r\n ],\r\n "has_more": false\r\n }\r\n}";
neb::CJsonObject oJson(data);
int a = 0;
oJson["data"]["items"][-1] .Get(0, a); //这样能正常获取a = 1

oJson["data"]["items"][0] .Get(0, a); //异常退出 !!!!!!!

parse_number函数解析double型value时结果不正确

在此函数中如下位置:
//printf("subscale = %d, signsubscale = %d, s = %.16f\n", subscale, signsubscale, d);
if (subscale != 0)
{
d = item->sign * base * pow(10.0, (scale + subscale * signsubscale)); /* number = +/- number.fraction * 10^+/- exponent /
}
item->valuedouble = d;
是不是应该改为:
if (subscale != 0)
{
item->valuedouble = item->sign * base * pow(10.0, (scale + subscale * signsubscale)); /
number = +/- number.fraction * 10^+/- exponent */
}else
{
item->valuedouble = item->sign * d;
}
// 在负数double数据时,d没有乘符号,导致负号消失,所以注释掉这句并修改上面的if语句
// item->valuedouble = d;

add

neb::CJsonObject oJson("{ "code": 111,"vv":"aaa","msg": "status", "data":[]}");
如上json,我要对data增加字段得到如下样式,
{ "code": 111,"vv":"aaa","msg":"status", "data":[{”aa“:12,"bb":34},{”aa“:12,"bb":34}]}
请问怎么实现呢?

大量数据json转换不推荐使用,有严重的性能问题

数组的动态增加有严重性能问题,直接导致整个函数执行速率下降了30倍左右
两个不同结构的相同数据,以下两种格式会相差30倍效率,前者20秒执行完,后者要10分钟
所有时间都花在了前两个“["Drones"][index]” 对应查询上了
`
相同执行频率,相同数据量,但是只是json格式不同
// 20 秒执行完
Channels_json["Channels"].Add(Channel_json);

// 10分钟执行完
drama_json["Drones"][index]["Channels"].Add(Channel_json);
`

如果这个不优化的话,建议不要使用,大量数据基本撑不住

转换的json数据量大概是200MB左右,如果只是小数据量不明显

优化建议

1、Replace 接口删除了原有的节点,再新增节点,导致节点迭代时出现野指针(cjson的节点结构是一个链表),希望不要删除而是修改。
2、Add 接口不应该添加同名称键,添加同名键可以报错或者覆盖原有值。
3、GetKey() 一个公有接口获取已有的建保留在内部,其意为何。
希望UP改进。

请问能否添加对于内存管理的钩子,就像cJSON那样?

我在使用C++开发单片机的时候,寻找到了您轻量级的基于cJSON封装的c++代码。但是在跑实时操作系统(FreeRTOS)的时候会卡死,调试发现我调用RTOS的申请内存接口,但在您代码里面直接用了free导致死机。我修改了您free的部分即可。所以希望可以给用户提供一个钩子,调用不同的内存管理接口。

遍历

请问如何遍历所有key和value 包括数组中的值

含有某些字导致Parse出现错误

你好,我发现某些字会导致Parse出现错误,比如“運”
以下代码可以重现这个错误:

neb::CJsonObject jObject;
if (jObject.Parse("{\"name\":\"運\"}"))
{
}

运行结果为Parse失败,把運字换成其他字成功,望修复。

parse 64bit integer failed on windows

On Windows platform, use visual studio community 2019 to excute following program,the 1903588763415872642 should be printed,but 1903588763415872512 got.

#include
#include "CJsonObject.hpp"

int main()
{
std::string test_str = "{"channelQueryId":1903588763415872642}";
auto co = neb::CJsonObject(test_str);
uint64_t id = 0;
co.Get("channelQueryId", id);
std::cout << id << std::endl;
return 0;
}

线程安全的问题

cJson异常处理用的是static 全局变量,因此是非线程安全的,咱们CJsonObject有对这部分做处理吗?还是说也只支持单线程?

CJSON版本

可以问一下基于的哪个版本的CJSON吗

建议加入覆盖处理的函数

使用CJsonObject::Replace()过程中如果出现对应键值项不存在时不会创建,所以在使用过程中如果需要判断Replace是否成功,如果为false则需要自行Add,建议加入:
bool CJsonObject::Override( ... )
{
if(Replace( ...) == false)
return Add( ...);
retrun true;
}
以实现覆盖功能,当没有待替换项时就创建它

建议增加AddRaw函数,可以用于浮点数输出精度控制

现在这个封装有个问题,无法控制浮点数的输出精度。

新的cjson里面有raw这个类型,可以直接写入原始字符,这样就由开发人员自行控制输出内容,可以解决精度问题。

或者直接增加Add精度参数也行,但是这样就和cjson差别更大了。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.