hello,
since my mailing reports were not accepted (yet), i try to post my problem from february 2011 here too!
back then i decided to use your library but got runtime errors on iterating through all the elements.
the end-loop-condition is never met and therefore crashes.
i debugged it and it seems there is a bug in the isequal check for end().
from "json_valueiterator.inl"
bool
ValueIteratorBase::isEqual( const SelfType &other ) const
{
#ifndef JSON_VALUE_USE_INTERNAL_MAP
if ( isNull_ )
{
return other.isNull_;
}
return current_ == other.current_;
#else
.....
#endif
}
i think the problem is in
void ValueIteratorBase::increment()
not setting
isNull_ = true;
and then failing at the isEqual method.
but since i cannot check there if the inside map interator is end() and then setting isNull_,
i am out of ideas right now.
i disabled the if isNull check in the isEqual method for now. so the actual interators of the internal
map are compared. this works, but i am not sure if this does have any side effects.
anyway, i thought i should let you know.
maybe you can check this and if it really is a bug, fix it.
hope this helps!
best regards,
Dietmar Suoch
---
my test code:
Json::Value jsonRoot;
Json::Reader jsonReader;
//blah blah ... parsing from stream -> OK.
//jsonRoot.size() != 0
Json::ValueIterator it; //or const
for (it = jsonRoot.begin(); it != jsonRoot.end(); ++it) //or it++
{
//crashes after
}
my input data:
{
"item1" :
{
"visible" : true
},
"item2" :
{
"visible" : true
},
"item4" :
{
"visible" : true
},
"item" :
{
"visible" : true
}
}
my build environment:
i am using revision 156 from the repository.
i did not do any config/install/make. i just use it in my MSVC solution.
build environment: visual studio 2009, windows xp sp3, x86, 32bit
Try this instead:
Json::ValueIterator it; //or const
for (it = jsonRoot.begin(); jsonRoot.end() != it; ++it) //or it++
{
//doesn't crash
}
uhm, really? this should be the solution?
i have not tried it and i believe you that it works.
i have solved or circumvented it myself (in a different way),
but i thought the purpose of reporting issues is to
improve software quality, not learn about some arcane tricks.
sorry, this just seems bad quality to me ...
i got this problem too...
can someone fix it?
i got this problem too...
can someone fix it?
i think these code can help:
ValueConstIterator &
ValueConstIterator::operator =( const ValueIteratorBase &other )
{
isNull_ = other.isNull_
copy( other );
return *this;
}
The unit-test
IteratorTest/distance
shows this to be fixed at: https://github.com/open-source-parsers/jsoncpp/Diff: