ptree p1,p2,p3;
p1 = pt.get_child("deviece");//访问多级节点中的数组数据
p2 = p1.begin()->second.begin()->second.begin()->second;
string id_str = p2.get<string>("id");
p3 = p2.get_child("dataItems").begin()->second.get_child("20000001").begin()->second;
string TV = p3.get<string>("TV");
string VA = p3.get<string>("VA");
string VB = p3.get<string>("VB");
string VC = p3.get<string>("VC");
string json_str = "{\"session\":\"a0011\",\"msgType\":\"req\",\"deviece\":[{\"device1\":[{\"id\":\"123\",\"dataItems\":[{\"20000001\":[{\"TV\":\"100.00\",\"VA\":\"65.30\",\"VB\":\"56.85\",\"VC\":\"120.30\"}]}]}]}]}";
list<dataitem_info> DataManager::GetDataItems_Cpp(string json_str , ptree xml_ptree)
{
list<dataitem_info> di_list;
try
{
Json::Reader reader;
Json::Value root;
if(reader.parse(json_str,root))
{
Json::Value dvc = root["deviece"];
for(Json::Value::iterator v = dvc.begin();v!=dvc.end();v++)
{
Json::Value dvs = (*v);
for(Json::Value::iterator v1 = dvs.begin();v1!=dvs.end();v1++)//device1,device2...
{
Json::Value dvs_in = (*v1);
for(Json::Value::iterator v2 = dvs_in.begin();v2!=dvs_in.end();v2++)
{
string id_str = (*v2)["id"].asString();
Json::Value dataItems = (*v2)["dataItems"];
for(Json::Value::iterator v3 = dataItems.begin();v3!=dataItems.end();v3++)
{
Json::Value dataItems_in = (*v3);
for(Json::Value::iterator v4 = dataItems_in.begin();v4!=dataItems_in.end();v4++)
{
string optStr = v4.memberName();
Json::Value db_keys = (*v4);
for(Json::Value::iterator v5 = db_keys.begin();v5!=db_keys.end();v5++)
{
Json::Value db_keys_in = (*v5);
for(Json::Value::iterator v6 = db_keys_in.begin();v6!=db_keys_in.end();v6++)
{
string db_name = v6.memberName();
}
}
}
}
}
}
}
}
}
catch (std::exception& e)
{
std::cout << "Error: " << e.what() << "\n";
}
return di_list;
}