garrettlynchirl
garrettlynchirl

Reputation: 910

How to parse JSON with Ofelia in Puredata

I'm trying to retrieve and parse some simple JSON from a url. This is what works so far for me (although I'm not sure if ofLoadURL is what I should be using - there seem to be many ways to retrieve content from a url):

ofelia f;
resp = ofLoadURL("https://api.nasa.gov/planetary/apod?api_key=DEMO_KEY&date=2024-06-06");
text = resp.data:getText();
print(text);
return(anything);

I can output it as text but cannot understand how to parse it from buffer or the string to JSON. I've been using this as an example (Iterating through objects in JsonCpp) so just to get one entry from the JSON should it be something like this? - not sure how to change it to work in Ofelia:

Json::Value root;
Json::Reader parser;

// Parse the json (using the text in the code above)
parser.parse( text, root );

// Get the url
print(root["url"]);

Upvotes: 0

Views: 31

Answers (0)

Related Questions