国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 編程 > C++ > 正文

C++中rapidjson組裝繼續(xù)簡(jiǎn)化的方法

2020-01-26 13:29:12
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

rapidjson組裝繼續(xù)簡(jiǎn)化------人生苦短,我用rapidjson

看最簡(jiǎn)單的:

#include <iostream>#include <stdio.h>#include<unistd.h>#include <sys/types.h>#include <sys/stat.h>#include <fcntl.h>#include<sstream>// 請(qǐng)自己下載開(kāi)源的rapidjson#include "rapidjson/prettywriter.h"#include "rapidjson/rapidjson.h"#include "rapidjson/document.h"#include "rapidjson/stringbuffer.h"#include "rapidjson/writer.h"#include "rapidjson/memorystream.h"using namespace std;using rapidjson::Document;using rapidjson::StringBuffer;using rapidjson::Writer;using namespace rapidjson;void test(){ Document document; document.SetObject(); Document::AllocatorType& allocator = document.GetAllocator(); Value object(rapidjson::kObjectType); document.AddMember("age", 29, allocator); document.AddMember("name", "taoge", allocator); StringBuffer buffer; Writer<StringBuffer> writer(buffer); document.Accept(writer); string str = buffer.GetString(); cout << str << endl;}int main(int argc, char *argv[]){ test(); return 0;}

結(jié)果:

{"age":29,"name":"taoge"}

再看數(shù)組:

#include <iostream>#include <stdio.h>#include<unistd.h>#include <sys/types.h>#include <sys/stat.h>#include <fcntl.h>#include<sstream>// 請(qǐng)自己下載開(kāi)源的rapidjson#include "rapidjson/prettywriter.h"#include "rapidjson/rapidjson.h"#include "rapidjson/document.h"#include "rapidjson/stringbuffer.h"#include "rapidjson/writer.h"#include "rapidjson/memorystream.h"using namespace std;using rapidjson::Document;using rapidjson::StringBuffer;using rapidjson::Writer;using namespace rapidjson;void test(){ Document document; document.SetObject(); Document::AllocatorType& allocator = document.GetAllocator(); Value array(rapidjson::kArrayType); Value object(rapidjson::kObjectType); object.AddMember("age", 30, allocator); object.AddMember("name", "taoge", allocator); array.PushBack(object, allocator); document.AddMember("json", array, allocator); StringBuffer buffer; Writer<StringBuffer> writer(buffer); document.Accept(writer); string str = buffer.GetString(); cout << str << endl;}int main(int argc, char *argv[]){ test(); return 0;}

結(jié)果:

{"json":[{"age":30,"name":"taoge"}]}

再來(lái)看一個(gè):

#include <iostream>#include <stdio.h>#include<unistd.h>#include <sys/types.h>#include <sys/stat.h>#include <fcntl.h>#include<sstream>// 請(qǐng)自己下載開(kāi)源的rapidjson#include "rapidjson/prettywriter.h"#include "rapidjson/rapidjson.h"#include "rapidjson/document.h"#include "rapidjson/stringbuffer.h"#include "rapidjson/writer.h"#include "rapidjson/memorystream.h"using namespace std;using rapidjson::Document;using rapidjson::StringBuffer;using rapidjson::Writer;using namespace rapidjson;void test(){ Document document; document.SetObject(); Document::AllocatorType& allocator = document.GetAllocator(); Value array(rapidjson::kArrayType); Value object(rapidjson::kObjectType); object.AddMember("age", 30, allocator); object.AddMember("name", "taoge", allocator); array.PushBack(object, allocator); document.AddMember("oh1", array, allocator); document.AddMember("oh2", "hehe", allocator); StringBuffer buffer; Writer<StringBuffer> writer(buffer); document.Accept(writer); string str = buffer.GetString(); cout << str << endl;}int main(int argc, char *argv[]){ test(); return 0;}

結(jié)果:

{"oh1":[{"age":30,"name":"taoge"}],"oh2":"hehe"}

總結(jié)

以上就是這篇文章的全部?jī)?nèi)容了,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,謝謝大家對(duì)武林網(wǎng)的支持。如果你想了解更多相關(guān)內(nèi)容請(qǐng)查看下面相關(guān)鏈接

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 桐柏县| 元阳县| 上饶市| 通渭县| 友谊县| 儋州市| 汤阴县| 崇州市| 手机| 永泰县| 石林| 青州市| 定西市| 大悟县| 凌云县| 福清市| 营口市| 永济市| 宽城| 乌兰察布市| SHOW| 久治县| 偏关县| 三亚市| 大名县| 宾川县| 九江县| 徐州市| 永仁县| 吴川市| 雷山县| 三穗县| 麦盖提县| 永嘉县| 友谊县| 碌曲县| 镇赉县| 潞西市| 玉屏| 镇沅| 梓潼县|