天道酬勤,学无止境

rapidjson

Processing arrays of arrays of integer with rapidjson

问题 查看 rapidjson 文档,建议使用此代码查询数组: for (Value::ConstValueIterator itr = a.Begin(); itr != a.End(); ++itr) printf("%d ", itr->GetInt()); 但是,我有一个数组数组,例如: [ [0,2], [1,2], [4, 5], ... ] 我想有一些用于处理它的两个级别,如下所示: for (Value::ConstValueIterator itr = a.Begin(); itr != a.End(); ++itr) for (Value::ConstValueIterator itr2 = itr->GetArray().Begin(); itr2 != itr->GetArray().End(); ++itr2) printf("%d ", itr2->GetInt()); 但是,似乎itr没有任何GetArray()或等效方法返回一个对象,在该对象中获取第二个(内部)迭代器。 注意:我找到了这篇问答帖子,但它似乎是基于获取一个表示内部数组的Value 。 但是,我不知道如何从itr迭代器中获取这样的值(例如, itr->value不起作用)。 回答1 #include <vector> #include <rapidjson/document.h>

2022-04-25 12:31:54    分类:技术分享    c++   rapidjson

rapidjson c++ deallocate Array within Object

问题 我正在使用 rapidjson C++ 库,使用这个库你可以创建一个 JSON 对象。 目前我有一些记忆问题。 情况: 在我当前的设置中,我创建了一个新对象,并为其添加了值成员和数组成员。 该对象通过引用传递给多个函数并在我的程序流程中使用。 rapidjson::Value data; data.SetObject(); while(...) { // -------------------------- // Add coordinates to object JSON::AllocatorType& allocator = data.GetAllocator(); JSONValue region; region.SetArray(); region.PushBack(rectangle.m_x1, allocator); region.PushBack(rectangle.m_y1, allocator); region.PushBack(rectangle.m_x2, allocator); region.PushBack(rectangle.m_y2, allocator); data.AddMember("regionCoordinates", region, allocator); // -------------------------- // Add

2022-04-21 07:29:54    分类:技术分享    c++   arrays   memory   rapidjson

How to parse array in root with rapidjason

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 which accepts a stringBuffer. It gives me back the nested string of array element. rapidjson

2022-04-16 08:59:17    分类:问答    c++   rapidjson

Compare rapidjson::Documents(Compare rapidjson::Documents)

问题

2022-04-16 08:48:03    分类:技术分享    c++   c   json   rapidjson

Processing arrays of arrays of integer with rapidjson

Looking to rapidjson documentation this code is suggested to query an array: for (Value::ConstValueIterator itr = a.Begin(); itr != a.End(); ++itr) printf("%d ", itr->GetInt()); However, I have an array of arrays, something like: [ [0,2], [1,2], [4, 5], ... ] I would like to have some two-levels for for processing it, something like this: for (Value::ConstValueIterator itr = a.Begin(); itr != a.End(); ++itr) for (Value::ConstValueIterator itr2 = itr->GetArray().Begin(); itr2 != itr->GetArray().End(); ++itr2) printf("%d ", itr2->GetInt()); However, it seems that itr doesn't have any GetArray()

2022-03-25 08:27:59    分类:问答    c++   rapidjson

rapidjson c++ deallocate Array within Object

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(); JSONValue region; region.SetArray(); region.PushBack(rectangle.m_x1, allocator); region.PushBack

2022-03-19 09:33:13    分类:问答    c++   arrays   memory   rapidjson

Compare rapidjson::Documents

I have two RapidJSON documents. One I created at runtime and other one is read from disk. I want to compare if these two documents are similar or not. What is the best way to compare RapidJSON documents? My JSON looks like this { "SimpleCompany:Manager": { "read":true, "update":true, "delete":true, "insert":true }, "SimpleCompany:Manager": { "read":true, "update":true, "delete":true, "insert":true }, }

2022-03-15 19:43:15    分类:问答    c++   c   json   rapidjson

Retrieving a nested object inside a JSON string using rapidjson

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() ) { std::cout << "OK" << std::endl; std::cout << document[ "a" ].GetString() << std::endl; } } This is the

2022-03-12 03:49:40    分类:问答    c++   json   rapidjson