欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

 更新時(shí)間:2019年04月08日 11:25:15   作者:stpeace  
今天小編就為大家分享一篇關(guān)于C++中rapidjson組裝繼續(xù)簡(jiǎn)化的方法,小編覺得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來看看吧

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)自己下載開源的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)自己下載開源的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"}]}

再來看一個(gè):

#include <iostream>
#include <stdio.h>
#include<unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include<sstream>
// 請(qǐng)自己下載開源的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ì)腳本之家的支持。如果你想了解更多相關(guān)內(nèi)容請(qǐng)查看下面相關(guān)鏈接

相關(guān)文章

  • c++快速排序詳解

    c++快速排序詳解

    快速排序總體思想:先找到一個(gè)樞軸,讓他作為分水嶺,通過一趟排序?qū)⒋判虻挠涗浄指畛蓛刹糠?前面一部分都比樞軸小,后面一部分樞軸大,然后又分別對(duì)這兩部分記錄繼續(xù)進(jìn)行遞歸的排序,達(dá)到整個(gè)序列有序的目的
    2017-05-05
  • C++設(shè)計(jì)模式之原型模式

    C++設(shè)計(jì)模式之原型模式

    這篇文章主要介紹了C++設(shè)計(jì)模式之原型模式,本文講解了什么是原型模式、為什么要使用原型模式、代碼實(shí)例等內(nèi)容,需要的朋友可以參考下
    2014-09-09
  • c++異常處理機(jī)制示例及詳細(xì)講解

    c++異常處理機(jī)制示例及詳細(xì)講解

    本篇文章主要是對(duì)c++異常處理機(jī)制示例進(jìn)行了介紹,需要的朋友可以過來參考下,希望對(duì)大家有所幫助
    2014-02-02
  • VC6.0如何創(chuàng)建以及調(diào)用動(dòng)態(tài)鏈接庫(kù)實(shí)例詳解

    VC6.0如何創(chuàng)建以及調(diào)用動(dòng)態(tài)鏈接庫(kù)實(shí)例詳解

    作為客戶與后臺(tái)的中介,為了更好的調(diào)節(jié)兩方的關(guān)系,我明智滴選擇了webservice以及動(dòng)態(tài)鏈接庫(kù)。在與客戶c++使動(dòng)態(tài)鏈接庫(kù)方式,而與后臺(tái)java,使用webservice來交流溝通
    2013-01-01
  • C/C++實(shí)操True and false詳解

    C/C++實(shí)操True and false詳解

    這篇文章主要給大家介紹了關(guān)于Python中常用的數(shù)據(jù)類型bool(布爾)類型的兩個(gè)值:True和False的相關(guān)資料,通過示例代碼給大家進(jìn)行了解惑,讓對(duì)這兩個(gè)值有所疑惑的朋友們能有起到一定的幫助,需要的朋友下面來一起看看吧。
    2021-09-09
  • C++深入淺出探索數(shù)據(jù)結(jié)構(gòu)的原理

    C++深入淺出探索數(shù)據(jù)結(jié)構(gòu)的原理

    C++的數(shù)據(jù)結(jié)構(gòu)很多,很復(fù)雜,所以本文將通過示例帶大家深入了解一下C++中的數(shù)據(jù)結(jié)構(gòu)與算法。文中的示例代碼講解詳細(xì),感興趣的可以了解一下
    2022-05-05
  • C++ STL入門教程(2) list雙向鏈表使用方法(附程序代碼)

    C++ STL入門教程(2) list雙向鏈表使用方法(附程序代碼)

    這篇文章主要為大家詳細(xì)介紹了C++ STL入門教程第二篇,list雙向鏈表使用方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-08-08
  • 使用matlab繪制七夕表白玫瑰花束

    使用matlab繪制七夕表白玫瑰花束

    又是一年七夕節(jié)要到了,每年一次直男審美MATLAB繪圖大賽開始了,于是今年對(duì)我之前寫的老代碼進(jìn)行了點(diǎn)優(yōu)化組合,整了個(gè)花球變花束,感興趣的小伙伴可以動(dòng)手試一試
    2023-08-08
  • C語言實(shí)現(xiàn)飛機(jī)訂票系統(tǒng)

    C語言實(shí)現(xiàn)飛機(jī)訂票系統(tǒng)

    這篇文章主要為大家詳細(xì)介紹了C語言實(shí)現(xiàn)飛機(jī)訂票系統(tǒng),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2019-12-12
  • C語言實(shí)現(xiàn)高精度加法的示例代碼

    C語言實(shí)現(xiàn)高精度加法的示例代碼

    高精度的本質(zhì)是將數(shù)字以字符串的形式讀入,然后將每一位分別存放入int數(shù)組中,通過模擬每一位的運(yùn)算過程,來實(shí)現(xiàn)最終的運(yùn)算效果,下面我們就來看看如何通過C語言實(shí)現(xiàn)高精度加法吧
    2023-11-11

最新評(píng)論