TalksonC++的JSON操作库

联合创作 · 2023-09-21

Talkson 是一个 C++ 库,包含 JSON 消息的编码和解码模块。是一个简单、轻量级的 JSON 解析器,无需依赖外部库,支持流数据解析。

将对象转成 JSON 字符串的示例代码:

// create a JSON value. This example uses the root object of the above example.
....

// serialize
JSONObjectSerializer encoder;

if( root->type == JSONValue::Object )
{
		pos = 0;
		encoder.open( root );
		while( (pos = encoder.encode( buf, BUF_SIZE )) > 0 )
				printf( "%.*s", pos, buf );
}
else if( root->type == JSONValue::Array )
{
		pos = 0;
		JSONArraySerializer encoder;
		encoder.open( root );
		while( (pos = encoder.encode( buf, BUF_SIZE )) > 0 )
				printf( "%.*s", pos, buf );
}

delete root;
浏览 4
点赞
评论
收藏
分享

手机扫一扫分享

编辑
举报
评论
图片
表情
推荐
点赞
评论
收藏
分享

手机扫一扫分享

编辑
举报