[property_tree] Serializing ptree to/from JSON
Hello, I am writing some code to serialize a package to/from JSON. Overall, it is working well, except for what appears to be a weak link in the ptree chain of events. I take a POCO (for all intents) and populate a ptree, then parse that to JSON using the property_tree JSON parser. No problem. Then I take that same string and want to parse it into another ptree. In and of itself, seems like it is no problem. The new ptree has a count, so I gather the parse worked. However, when I try to use ptree.count(path), or ptree.find(path), neither of these work. They are returning 0 or not_found(), respectively. I may be able to bypass that check for the moment and run it through ptree.get<Type>(path) for the time being, but that seems less desirable. Any insights on ptree along these lines? Thanks! Regards, Michael Powell
Looking for someone's help me to make correct use of boost composite key.
Requirement:
Given config and type get all cid's
Below example I am passing config =1; and type = 1; I am expecting all cid's matching both of them. i.e 1 and 2 only
However if you see the out output it is: 1,2,3,1,8,3
//----------
#include
recordBookDef;
recordBookDef recordbook;
int main()
{
record obj1(1,1,1);
record obj2(2,2,1);
record obj3(3,3,1);
recordbook.insert(obj1);
recordbook.insert(obj2);
recordbook.insert(obj3);
record obj11(2,1,1);
record obj12(1,2,1);
record obj13(8,2,1);
recordbook.insert(obj11);
recordbook.insert(obj12);
recordbook.insert(obj13);
unsigned int config =1;
unsigned int type = 1;
recordBookDef::iterator it=recordbook.find(boost::make_tuple(config,type));
while(it!=recordbook.end())
{
//if(it->config == 1)
std::cout<<it->config<<",";
++it;
}
std::cout<
Requirement: Given config and type get all cid's Below example I am passing config =1; and type = 1; I am expecting all cid's matching both of them. i.e 1 and 2 only
You probably meant to use equal_range(), not find(). find() returns you an iterator to the 1st element having the desired key, so if you iterate an ordered index from this point to the end, you get all the elements having a greater or equal key.
Thanks Igor. It solved my problem. Regards, UJ
participants (3)
-
Igor R
-
Michael Powell
-
Uthpal Urubail