linux c++json文字列解析

12240 ワード

これはjsoncpp解析文字列をテストする小さなプログラムで、雑然としていて、好きではありません.

#include "./include/config.h"
int main_()
{
  char buf[4096] = {0};
  // FILE* file = fopen("JsonText", "r");
  ifstream in("config.json", ios::binary);

  if (!in.is_open())
  {
    cout << "Error opening file
"
; return 0; } // fread(file, 4096, ); // buf[4095] = '\0'; // cout << buf; Json::Value root; Json::Reader reader; // char JsonText[10] = {0}; reader.parse(epJosn, root); in.close(); char epValue[] = "false"; uint8_t dest[32] = {0}; // json cout << "1" << endl; const char *jsonValue = root["1"][epValue].asCString(); cout << "2" << endl; cout << "jsonValue" << jsonValue << endl; int epVLen = strlen(jsonValue) / 2; str2uint8s(dest, jsonValue, epVLen); printf(" strlen(jsonValue) :%d ", epVLen); printf("
"
); for (size_t i = 0; i < epVLen; i++) { printf("%02X ", dest[i]); } printf("
"
); cout << "===============================
"
; cout << root; cout << "===============================
"
; Json::Value a = root["111"]; cout << endl; if (a.isNull() == true) { cout << "null l" << endl; } // vector::const_iterator iter = root["3"].getMemberNames().begin(); // int i = 0; // cout << root["3"]; // cout << root["3"]["3"].isNull() << endl; // if (root["3"].isMember("3")) // { // cout << root["3"]["3"] << endl; // cout << "shichengyuan" << endl; // } // cout << root["3"]["4"] << endl; // cout << root["3"]["5"] << endl; // cout << root["3"]["6"] << endl; // cout << root["3"]["2"] << endl; // cout << root.isMember("13") << endl; cout << root["13"] << endl; cout << root["7"] << endl; cout << root["13"].asCString() << endl; // // cout<< // cout << *(root["3"].getMemberNames().end()) << endl; // while (iter != root["3"].getMemberNames().end()) // { // // if (root["3"][*iter].isNull() == true) // // { // // break; // // } // i++; // cout << i << endl; // // if (!strcasecmp("A90001000001019A", root["3"][*iter].asCString())) // // { // // cout << " " << endl; // // } // cout << root["3"][]; // iter++; // } // root["3"].getMemberNames().begin(); // if () // { // cout << "shifou"; // } // cout << root << endl; return 0; }