rapidjson

rapidjson - change key to another value

风格不统一 提交于 2019-12-12 12:13:49
问题 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-

json Comparison in c++

折月煮酒 提交于 2019-12-12 06:39:12
问题 I am a little stuck here can anyone help please. #include <iostream> #include "include/rapidjson/document.h" #include "include/rapidjson/writer.h" #include "include/rapidjson/prettywriter.h" //#include "include/rapidjson/stringbuffer.h" using namespace std; using namespace rapidjson; class test { public: static bool isEqual(const string &item1, const string &item2, const string &temp) { Document d1; d1.Parse(item1.c_str()); Document d2; d2.Parse(item2.c_str()); Document d3; d3.Parse(temp.c

Rapidjson does not encode utf8 sequence at all

我怕爱的太早我们不能终老 提交于 2019-12-11 13:06:27
问题 I'm trying to use rapidjson to escape utf8 sequences to \uXXXX format, but it's not working. StringBuffer s; Writer<StringBuffer, Document::EncodingType, ASCII<> > writer(s); writer.StartObject(); writer.String("chinese"); writer.String("中文测试"); writer.EndObject(); cout << s.GetString() << endl; The document says it would be escaped but actually it's all erased. I tried to use AutoUTF template, but here's no document for memory stream either Any ideas? I tried jsoncpp as well, but that

Rapidjson cannot copy `rapidjson::Document`

余生长醉 提交于 2019-12-11 09:55:47
问题 I need a function that constructs a rapidjson::Document and returns. But when I write a function with this prototype: rapidjson::Document progressToJson(const Progress& progress); I get this error: error LNK2019: unresolved external symbol "private: __thiscall rapidjson::GenericValue<struct rapidjson::UTF8<char>,class rapidjson::MemoryPoolAllocator<class rapidjson::CrtAllocator> >::GenericValue<struct rapidjson::UTF8<char>,class rapidjson::MemoryPoolAllocator<class rapidjson::CrtAllocator> >

How to parse array in root with rapidjason

扶醉桌前 提交于 2019-12-11 07:24:52
问题 I have follwing code. Document d; const char* json = "[{\"k1\":\"1\"}, {\"k1\":\"2\"}]"; d.Parse(json); for (SizeType i = 0; i < d.Size(); i++) { cout << d[i]["k1"].GetInt() << "\n"; } I get below error when I run this: rapidjson/include/rapidjson/document.h:1700: int rapidjson::GenericValue<Encoding, Allocator>::GetInt() const [with Encoding = rapidjson::UTF8<>; Allocator = rapidjson::MemoryPoolAllocator<>]: Assertion `data_.f.flags & kIntFlag' failed. One way I figured out is using writer

rapidjson c++ deallocate Array within Object

拥有回忆 提交于 2019-12-11 03:30:50
问题 I'm using the rapidjson C++ library, with this library you can create a JSON object. Currently I'm having some memory issues. The situation: In my current setup I’ve created a new object, and added value members and an array member to it. The object is passed by reference to multiple functions and used in the flow of my program. rapidjson::Value data; data.SetObject(); while(...) { // -------------------------- // Add coordinates to object JSON::AllocatorType& allocator = data.GetAllocator();

Compare rapidjson::Documents

…衆ロ難τιáo~ 提交于 2019-12-10 11:22:48
问题 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 }, } 回答1: Yes, now, GenericValue overrides the operator== with other values, strings or

get array data from json file using rapidjson

蓝咒 提交于 2019-12-08 17:12:11
问题 I'm new in rapidjson. I have test.json which contains {"points": [1,2,3,4]} and I use following code to get data of array "points" std::string fullPath = CCFileUtils::sharedFileUtils()->fullPathForFilename("json/deluxe/treasurebag.json"); unsigned long bufferSize = 0; const char* mFileData = (const char*)CCFileUtils::sharedFileUtils()->getFileData(fullPath.c_str(), "r", &bufferSize); std::string clearData(mFileData); size_t pos = clearData.rfind("}"); clearData = clearData.substr(0, pos+1);

How can I add members to a rapidjson document using integers as the key/name?

≡放荡痞女 提交于 2019-12-08 06:20:55
问题 I'm using a for loop and want to use the iterator, i, as the key/name when I add a member to the document. For example I want the document to look like this: {"1":"123.321","2":"456.654"} Here is what I have tried so far. 1. Converting i to a const char* rapidjson::Value newDouble(6); for(int i = 0;i<laserScan.size();i++){ newDouble.SetDouble(laserScan[i]); const char* index = std::to_string(i).c_str(); d.AddMember(index,newDouble,d.GetAllocator()); } This generates a compiler error telling

rapidjson pretty print using JSON string as input to the writer

こ雲淡風輕ζ 提交于 2019-12-07 21:24:38
问题 Following rapidjson documentation I'm able to generate a pretty-printed JSON ouput writting in a key-by-key approach, e.g.: rapidjson::StringBuffer s; rapidjson::PrettyWriter<rapidjson::StringBuffer> writer(s); writer.StartObject(); writer.Key("hello"); writer.String("world"); writer.EndObject(); std::string result = s.GetString(); However, I would like to do the same but using a JSON string (i.e. a std::string object which content is a valid JSON) to feed the writer, instead of calling Key()