示例#1
0
void print_search_results(json::value const & value)
{
	if (!value.is_null())
	{
		//auto response = value.at(L"data");
		//auto results = response[L"movies"];

		// iteration is supported not directly on json::value but on 
		// json::object and json::array. Use json::value::as_object() and json::value::as_array().
		std::wcout << value.as_array().at(0) << std::endl;
		for (auto const & o : value.as_array())
		{
			auto id = o.at(L"id");
			auto name = o.at(L"name");
			auto username = o.at(L"username");
			auto email = o.at(L"email");
			auto address = o.at(L"address");
			auto street = address.at(L"street");
			
			std::wcout << id << std::endl << name << std::endl << username << std::endl << email << std::endl << street << std::endl << std::endl;
		}
	}
}
示例#2
0
void GoogleSearchClient::flattenJsonInnerLoop(json::value const & val, FlatJsonObject & json_map) {
  // input : Body of the google search response as json::value
  // This recursive function parse the Json raw value to a C++ multimap
  if (!val.is_null() && val.is_object()) {
    for (auto const &iter : val.as_object()) {
      //iter on each element for Json object type. Return a vect<string_t,json::value>
      const auto &mapKey = iter.first;
      const auto &content = iter.second;
      json_map.insert(std::pair<utility::string_t, utility::string_t>(mapKey, content.serialize()));
      flattenJsonInnerLoop(content, json_map);
    }
  } else if (val.is_array()) {
    for (auto const &content : val.as_array()) {
      //iter on each element for Json array type. Return a json::value
      flattenJsonInnerLoop(content, json_map);
    }
  }
}