[libjsoncpp] libjsoncpp demo

#include 
#include 
#include 
#include "jsoncpp/json/json.h"

using namespace std;

int main(int argc, char **argv)
{

  std::string jsonStr1 = "{";
  jsonStr1 += "\"list\":[";
  jsonStr1 += "\"com.dummy.app\",";
  jsonStr1 += "\"com.dummy1.app\",";
  jsonStr1 += "\"com.dummy2.app\",";
  jsonStr1 += "\"com.dummy3.app\",";
  jsonStr1 += "\"com.dummy4.app\",";
  jsonStr1 += "\"com.dummy5.app\"],";
  jsonStr1 += "\"year\":{";
  jsonStr1 += "\"^2024\":[";
  jsonStr1 += "\"+com.dummy2024.app2\",";
  jsonStr1 += "\"-com.dummy3.app\"],";
  jsonStr1 += "\"^2024&^2027\":[";
  jsonStr1 += "\"+com.dummy2025.app\",";
  jsonStr1 += "\"+com.dummy4.app\"]},";
  jsonStr1 += "\"NNN\":[";
  jsonStr1 += "\"+com.dummy.app2\",";
  jsonStr1 += "\"-com.dummy.app\"],";
  jsonStr1 += "\"NNN1\":[";
  jsonStr1 += "\"+com.dummy.app2\",";
  jsonStr1 += "\"-com.dummy.app\"]}";

  Json::Reader json_reader;
  Json::Value json_value;

  std::string errors{};
  json_reader.parse(jsonStr1.c_str(), jsonStr1.c_str() + jsonStr1.length(), json_value, &errors);

  const Json::Value& v = json_value["year"];

  printf("year:%s\n",v.toStyledString().c_str());

  for(auto a:v.getMemberNames()){
          printf("%s\n",a.c_str());
    for(int i =0; i < v[a.c_str()].size(); i++){
        printf("%s\n",v[a.c_str()][i].asString().c_str());
    }
  }

}

编译:

g++ -std=c++11 3.cpp -ljsoncpp -o 3

你可能感兴趣的:(Lib,libjsoncpp)