Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rapidjson why i can query array with index only with ConstValueIterator in c++ #802

Closed
meiry opened this issue Dec 2, 2016 · 1 comment

Comments

@meiry
Copy link

meiry commented Dec 2, 2016

Hello all , just started to use the this great lib and i have question :
i have this simple part of json :

"foo" : [{
				"Name" : "t1",
				"things" : []
			}, {
				"name" : "t2",
				"things" : []
			}
		],

Array that contains objects , this is part of much larger json
rapidjson::Value& foo = jsonValue["foo"];
constructFoo(&foo);

This is the function that iterate the array of objects

constructFoo(rapidjson::Value* jsonValue)
{
for (rapidjson::SizeType i = 0; i < jsonValue->Size(); i++) 
	{
		rapidjson::Value& fooObj = jsonValue[i];
    }

}

The jsonValue->Size() value is 2
but the fooObj keep return the all Array foo
and not the object per index

This on the other hard works fine ,

for (rapidjson::Value::ConstValueIterator itr = jsonValue->Begin(); itr != jsonValue->End(); ++itr)
	{
		rapidjson::Type tt = itr->GetType();  // Is type Object 
		 
            
	}

What is the difference ? why simple index based loop don't work ?

@miloyip
Copy link
Collaborator

miloyip commented Dec 2, 2016

Since jsonValue is a pointer in:

constructFoo(rapidjson::Value* jsonValue)

So you need to dereference it to use operator[], e.g.

rapidjson::Value& fooObj = (*jsonValue)[i];

@esrrhs esrrhs closed this as completed Nov 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants