Got a minute? We appreciate your feedback:

Graphisoft Learn survey
Archicad C++ API
About Archicad add-on development using the C++ API.

Need Restful API functionality

Anonymous
Not applicable
Hi
I noticed that there are header files for HTTP and JSON. Does Archicad 22 have the ability to do Restful calls?
I have tried, with no luck, to get 3rd party Casablanca HTTP library to work in a project.
Please help

Archicad 22
Windows
5 REPLIES 5

Anonymous
Not applicable
Ok I have found examples in Goodies example project. Now having a problem with Casting to Json object, throws an exception. I am able to retreive the response data as text but I really need a JSON object

/* throws exception at GS::DynamicCast<JSON::ObjectValue>(parsed); */
DBPrintf("HTTP %u\n", response.GetStatusCode());
if (response.GetStatusCode() == StatusCode::OK) {

JSON::ObjectValueRef object = GS::DynamicCast<JSON::ObjectValue>(parsed);
JSON::StringValueRef tokenValue = GS::DynamicCast<JSON::StringValue>(object->Get("regionName"));
if (tokenValue != nullptr) {
GS::UniString token = tokenValue->Get();
DBPrintf("NBS Token: %s\n", token.ToCStr().Get());
}
}



/* Working but text only */
SAJParser saxParser;
ExampleSAJParseTracer testSAXParseTracer;

saxParser.Parse(clientConnection.BeginReceive(response), testSAXParseTracer);
if (testSAXParseTracer.ParseFinished()) {
DBPrintf("The content of the JSON file was:\n%s\n", testSAXParseTracer.GetOutput().ToCStr(0, MaxUSize, CC_UTF8).Get());
}

clientConnection.FinishReceive();
clientConnection.Close(false);

}
catch ( std::exception&)
{
std::string error;
}

Danny Sparks-Cousins
Contributor
Has anyone else worked with the JSON parsing in the ArchiCAD API? I am facing a similar problem to Bianca's example above.

I can get the response data as text no worries, but cannot seem to get a member string value cast to GS::UniString.

Anonymous
Not applicable
Use a JSON::JDOMParser to parse the client's response into a JSON object:

HTTP::Client::Response response;
JSON::JDOMParser parser;
JSON::ValueRef parsed = parser.Parse(client->BeginReceive(response));

// check statuscode
auto statusCode = response.GetStatusCode();

if (statusCode == HTTP::MessageHeader::StatusCode::OK) {
JSON::ObjectValueRef object = GS::DynamicCast<JSON::ObjectValue>(parsed);
// do whatever you need with 'object'
}

Mihalcea Bogdan
Contributor
Kengey wrote:
Use a JSON::JDOMParser to parse the client's response into a JSON object:

HTTP::Client::Response response;
JSON::JDOMParser parser;
JSON::ValueRef parsed = parser.Parse(client->BeginReceive(response));

// check statuscode
auto statusCode = response.GetStatusCode();

if (statusCode == HTTP::MessageHeader::StatusCode::OK) {
JSON::ObjectValueRef object = GS::DynamicCast<JSON::ObjectValue>(parsed);
// do whatever you need with 'object'
}
Can you please write some code after "//do whatever you want", like how to get values from the object?

Mihalcea Bogdan
Contributor
I found another parser here.
C:\Program Files\GRAPHISOFT\API Development Kit 24.3009\Support\Modules\RapidJSON
Documentation for rapidJSON

It gave me better results and the code is much more readable.

Didn't find the answer?

Check other topics in this Forum

Back to Forum

Read the latest accepted solutions!

Accepted Solutions

Start a new conversation!