How to use json data from api?

Hi!

I getting data from an api:

ofHttpResponse resp = ofLoadURL(“https://api.sunrise-sunset.org/json?lat=14.5958&lng=120.9772&callback=mycallback”);

I’m able to get the data into OF it return the data in a json format:

{
“results”:
{
“sunrise”:“7:27:02 AM”,
“sunset”:“5:05:55 PM”,
“solar_noon”:“12:16:28 PM”,
“day_length”:“9:38:53”,
“civil_twilight_begin”:“6:58:14 AM”,
“civil_twilight_end”:“5:34:43 PM”,
“nautical_twilight_begin”:“6:25:47 AM”,
“nautical_twilight_end”:“6:07:10 PM”,
“astronomical_twilight_begin”:“5:54:14 AM”,
“astronomical_twilight_end”:“6:38:43 PM”
},
“status”:“OK”
}

How can i get the directories of json data to work with it? let’s say i only want the sunrise time.

I need json library?

Heyho, open frameworks includes ofJson.
OfJson is an alias to GitHub - nlohmann/json: JSON for Modern C++

Here is an example: openFrameworks/examples/input_output/jsonExample at master · openframeworks/openFrameworks · GitHub

Hope that helps

1 Like

Thomas, thanks a lot will take a look.