linux c++ json字符串解析

这个是测试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\n";
    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("\n");
  for (size_t i = 0; i < epVLen; i++)
  {
    printf("%02X ", dest[i]);
  }
  printf("\n");
  cout << "===============================\n";
  cout << root;
  cout << "===============================\n";
  Json::Value a = root["111"];
  cout << endl;
  if (a.isNull() == true)
  {
    cout << "null   l" << endl;
  }
  // vector<Member>::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;
}
发布了148 篇原创文章 · 获赞 19 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/weixin_44580977/article/details/103781791