Can I return ofJson from a function? Should I use a ofJson Variable

I am making a class containing this function,

ofJson APILoad::urlLoader(string url, string file)
{
Response = ofLoadURL(url);

myBuffer = Response.data;

ResponseStr = myBuffer.getData();

cout << "  " << ResponseStr;

FILE *fp;

fp = fopen(file.c_str, "w");

fprintf(fp, "%s", ResponseStr.c_str());

fclose(fp);

fflush(fp);

json = ofLoadJson(file);

return(json);

}

According to the question above, is the correct format?

Lots of documentation missing from ofJson it seems, any good resources?

Hi, there is no need to write to a file, unless you want it to be that way.

ofJson APILoad::urlLoader(string url)
{
    Response = ofLoadURL(url);
    try {
        return ofJson::parse(Response.data.getText());
     }
    catch (ofJson::parse_error& ex)
    {
        return ofJson();
    }
}

ofJson is just a name alias for nlohmann::json which has a very good documentation.

1 Like