58 lines
1.5 KiB
C++
58 lines
1.5 KiB
C++
|
#include <iostream>
|
|||
|
#include <string>
|
|||
|
#include <assert.h>
|
|||
|
#include <unistd.h>
|
|||
|
|
|||
|
#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]; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
|||
|
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;
|
|||
|
}
|