Skip to content

getting error terminate called after throwing an instance of 'std::domain_error' what(): cannot use at() with string #1582

Closed
@Munodiwa

Description

After performing a http get request I receive a json string containing a string. I need to access the link inside this json string. I am using ubuntu. I downloaded the package with the cmd line sudo apt-get install nlohmann-json-dev

#include <stdio.h>
#include <stdlib.h>
#include "json.hpp"
#include <curl/curl.h>
#include

using nlohmann::json;

int main()
{
curl_global_init( CURL_GLOBAL_ALL );
CURL * myHandle;
CURLcode result; // We’ll store the result of CURL’s webpage retrieval, for simple error checking.
myHandle = curl_easy_init ( ) ;
// Notice the lack of major error checking, for brevity
curl_easy_setopt(myHandle, CURLOPT_URL, "https://matiusulung.com/se.json");
result = curl_easy_perform( myHandle);
json object = "(result)";
std::cout<<object.at("link").getstd::string();
curl_easy_cleanup( myHandle );
printf("LibCurl rules!\n");
return 0;

}

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions