C++解析JSON格式的類庫:Talkson
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;
本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!