"libjsoncpp"
json不支持8进制和16进制数值转换。
#include "json/json.h"
Json::Reader reader;
Json::Value root;
std::ifstream in("/data/shared/info.json", std::ios::binary);
if(!in.is_open())
{
ALOGE("[%s] Error opening file", __func__);
return;
}
if(reader.parse(in, root))
{
int node_size = root["Information"].size();
ALOGI("[%s] node_size: %d", __func__, node_size);
for(auto const & node : root["Information"])
{
std::string code = node["Code"].asString();
std::string info = node["Context"].asString();
uint32_t value = static_cast<uint32_t>(std::stoul(code.c_str(), nullptr, 16));
ALOGI("[%s] code: %x", __func__, value);
ALOGI("[%s] info: %s", __func__, info.c_str());
}
in.close();
}
else
{
ALOGE("[%s] reader parse file failed", __func__);
}
{
"Information" : [
{
"Code" : "0x11111111",
"Context" : "..."
},
{
"Code" : "0x22222222",
"Context" : "..."
}
]
}