#include #include #include #include #include "openjson.h" int main() { using namespace std; char *pbuf = get_current_dir_name(); std::cout << "current path is " << pbuf << std::endl; std::string filepath(pbuf); filepath = filepath + "/" + "mqtt-from-ems.json"; OpenJson json; if (!json.decodeFile(filepath)) { std::cout << "failed to load " << filepath << std::endl; free(pbuf); return -1; } std::string fsucode = json["FsuCode"].s(); std::string dev_type = json["type"].s(); std::string timestamp = json["TimeStamp"].s(); std::cout << "FsuCode: " << fsucode << std::endl; std::cout << "type: " << dev_type << std::endl; std::cout << "TimeStamp: " << timestamp << std::endl; auto& IdCodeContent = json["IdCodeContent"]; assert(IdCodeContent.size() > 0); std::cout << std::endl; std::cout << "Node size: " << IdCodeContent.size() << std::endl; for (size_t k = 0; k < IdCodeContent.size(); k++) { auto& pNode = IdCodeContent[k]; //这是其中的一个参数 std::string oid = pNode["OID"].s(); std::string value = pNode["Value"].s(); std::string factor = pNode["Factor"].s(); std::cout << "\tOID: " << oid << std::endl; std::cout << "\tValue: " << value << std::endl; std::cout << "\tFactor: " << factor << std::endl; std::cout << std::endl; } free(pbuf); return 0; }