/* Parse a raw string into Value object using the CharReaderBuilder class, or the legacy Reader class. Example Usage: $g++ readFromString.cpp -ljsoncpp -std=c++11 -o readFromString $./readFromString colin 20.  */
int jsoncpp_comp_read_string_example(int argc, char **argv)
/* Parse a raw string into Value object using the CharReaderBuilder class, or the legacy Reader class. Example Usage: $g++ readFromString.cpp -ljsoncpp -std=c++11 -o readFromString $./readFromString colin 20.  */
int jsoncpp_comp_read_string_example(int argc, char **argv)
{
  const std::string rawJson = R"({"Age": 20, "Name": "colin"})";
  const auto rawJsonLength = static_cast<int>(rawJson.length());
  constexpr bool shouldUseOldWay = false;
  JSONCPP_STRING err;
  Json::Value root;
  if (shouldUseOldWay) {
    Json::Reader reader;
    reader.parse(rawJson, root);
  } else {
    Json::CharReaderBuilder builder;
    const std::unique_ptr<Json::CharReader> reader(builder.newCharReader());
    if (!reader->parse(rawJson.c_str(), rawJson.c_str() + rawJsonLength, &root,
                       &err)) {
      printf("Read json error!\r\n");
      return EXIT_FAILURE;
    }
  }
  const std::string name = root["Name"].asString();
  const int age = root["Age"].asInt();
  printf("json read name = %s !\r\n", name.c_str());
  printf("josn read age = %d !\r\n", age);
  return EXIT_SUCCESS;
}