Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <sstream>
- #include <cpr/cpr.h>
- #include <json.hpp>
- void appInit(char *args) {
- }
- int main(int argc, char *argv) {
- if (argc > 1) {
- appInit(argv);
- } else {
- std::cout << "Usage: a.out [search keyword]" << std::endl;
- }
- int limit = 3;
- cpr::Parameters parameters{{"query", input},
- {"limit", "3"},
- {"indent", "true"},
- {"key", "AIzaSyA5Xr82w7LrJgaLPb99P4kVZzFlxYuPhng"}};
- auto response = cpr::Get(cpr::Url{
- "https://kgsearch.googleapis.com/v1/entities:search"}, parameters);
- auto json = nlohmann::json::parse(response.text);
- json.flatten();
- for (int i=0; i<limit; i++) {
- std::ostringstream oss;
- std::cout << json["/itemListElement/0/result/name"_json_pointer];
- //std::cout << json["/itemListElement/i/result/@type/0"_json_pointer] << std::endl;
- //std::cout << json["/itemListElement/i/result/@type/1"_json_pointer] << std::endl;
- std::cout << json["/itemListElement/0/result/description"_json_pointer] << std::endl;
- std::cout << json["/itemListElement/0/result/detailedDescription/articleBody"_json_pointer] << std::endl;
- std::cout << json["/itemListElement/0/result/image/url"_json_pointer] << std::endl;
- }
- //std::cout << json.dump(4) << std::endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement