rapidjson

iterate and retrieve nested object in JSON using rapidjson

依然范特西╮ 提交于 2019-12-07 04:40:58
问题 I am parsing a JSON structure which is similar as follows { "item1" : "value1" "item2" : "value2" // ... "itemn" : { "outernestedItem1" : { "innerNestedItem1" : "valuen1" "innerNestedItem2" : "valuen2" } // .... "outernestedItemn" : { "innerNestedItem1" : "valuen1" "innerNestedItem2" : "valuen2" } } } The number of outer nested items is not fixed, so I was iterating using iterator from rapidjson, inner-nested objects variables are fixed, so I can get access to them using []. const rapidjson:

Set floating point precision using rapidjson

北城余情 提交于 2019-12-06 08:22:27
问题 Is there a way to control the output precision in JSON generated using rapidjson? For example: writer.String("length"); writer.Double(1.0 / 3.0); This generates something like: { length: 0.33333333 } I'm sending a lot of values and only need two decimal places for several values. 回答1: From sources Writer& Double(double d) { Prefix(kNumberType); WriteDouble(d); return *this; } //! \todo Optimization with custom double-to-string converter. void WriteDouble(double d) { char buffer[100]; #if _MSC

Compare rapidjson::Documents

旧城冷巷雨未停 提交于 2019-12-06 07:58:26
I have two Rapid Jason documents. one I created at run time and other one is read from disk I want to compare these two documents that they are similar or not. what is best way to compare rapidJson documents. My josn looks like this { "SimpleCompany:Manager": { "read":true, "update":true, "delete":true, "insert":true }, "SimpleCompany:Manager": { "read":true, "update":true, "delete":true, "insert":true }, } Yes, now, GenericValue overrides the operator== with other values, strings or primitives: bool operator==(const GenericValue<...>& rhs) const; bool operator==(const Ch* rhs) const; bool

iterate and retrieve nested object in JSON using rapidjson

别说谁变了你拦得住时间么 提交于 2019-12-05 08:02:20
I am parsing a JSON structure which is similar as follows { "item1" : "value1" "item2" : "value2" // ... "itemn" : { "outernestedItem1" : { "innerNestedItem1" : "valuen1" "innerNestedItem2" : "valuen2" } // .... "outernestedItemn" : { "innerNestedItem1" : "valuen1" "innerNestedItem2" : "valuen2" } } } The number of outer nested items is not fixed, so I was iterating using iterator from rapidjson, inner-nested objects variables are fixed, so I can get access to them using []. const rapidjson::Value& itemn = document["itemn"]; for (rapidjson::Value::ConstMemberIterator itr = itemn.MemberBegin();

Retrieving a nested object inside a JSON string using rapidjson

坚强是说给别人听的谎言 提交于 2019-12-03 17:10:56
问题 I need to retrieve a nested object inside a JSON string and I'm trying to do it using rapidjson. All I've found is how to retrieve arrays and basic types, but not sub-objects. I have created the following toy example which gives an error: rapidjson::Document document; std::string test = " { \"a\": { \"z\" : 21 } } "; std::cout << test << std::endl; if ( document.Parse<0>( test.c_str() ).HasParseError() ) { std::cout << "Parsing error" << std::endl; } else { if ( document[ "a" ].IsObject() ) {

rapidjson - change object - add element/item

匿名 (未验证) 提交于 2019-12-03 10:24:21
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: how do I add a member to a rapidjson object and then print it? for example add itemtwo => "world" ; to this object: {"itemone":"hello"} I tried char buff[] = "{\"itemone\":\"hello\"}"; rapidjson::Document json_obj; if(json_obj.Parse<0>(buff.c_str()).HasParseError() == false){ json_obj["itemtwo"].SetString("world"); rapidjson::StringBuffer strbuf; rapidjson::Writer<rapidjson::StringBuffer> writer(strbuf); json_obj.Accept(writer); cout<<strbuf.GetString()<<endl; } I get the following output: {"itemone":"hello"} meaning no change. What am I

rapidjson - change key to another value

匿名 (未验证) 提交于 2019-12-03 00:52:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Here is the hello world of rapidjson. How can I change key "hello" to "goodbye" and get string from the json? I mean I want to parse json, change some keys and get json string back like {"goodbye" : "world"} . const char json[] = "{ \"hello\" : \"world\" }"; rapidjson::Document d; d.Parse<0>(json); 回答1: const char *json = R"({"hello": "world"})"; rapidjson::Document d; d.Parse<0> (json); rapidjson::Value::Member* hello = d.FindMember ("hello"); if (hello) { d.AddMember ("goodbye", hello->value, d.GetAllocator()); d.RemoveMember ("hello"); }

RapidJson简单使用(1)

匿名 (未验证) 提交于 2019-12-03 00:30:01
RapidJson是一个C++的JSON解析器和生成器。RapidJson具有小而全,高性能,跨平台、不依赖外部库而独立,对Unicode友好和内存友好等特点。 RapidJson依赖cmake作为通用生成工具,以Ubuntu为例,安装步骤如下: 1.下载RapidJson库: #git submodule update --init 2.在RapidJson库目录下,创建一个build目录: #mkdir build 3.在build目录下执行: #cmake .. 4.在 Linux/Ubuntu 下,于 build 目录运行: #make 注意:在 Windows 下,编译生成在 build 目录中的 solution。 5.在buil目录下执行: #make install #include <iostream> #include <string> #include <assert.h> #include "rapidjson/document.h" #include "rapidjson/writer.h" #include "rapidjson/stringbuffer.h" using namespace std ; using namespace rapidjson; int main( void ) { //1.把Json解析至DOM //const char

LNK2019: “Unresolved external symbol” with rapidjson

删除回忆录丶 提交于 2019-12-02 04:54:00
问题 I have a Visual C++ Project in which I added the rapidjson library, which is tested to be working properly. But when I add a rapidjson::Document type to the nested class is throwing a LNK2019 error when I try to compile. The project is a dynamic library to create a DLL. This are the definitions in my main.h : class coreBD { string conn; string proxy; int type; Document test; enum dataBases { Sqlite, SqlServer, None }; string queryBD(string sSQL); string queryHTTP(string sSQL); string