How to convert JSON stirng to struct object

68 views
Skip to first unread message

Kumar

unread,
Dec 4, 2017, 9:20:01 AM12/4/17
to ngrest
Hi All,

Inside my service API calling some other API which is returning JSON string.

I want to read JSON and convert it to struct object.

Could you please help me how to convert and which API to use to do the same.

Thanks.



Dmitry Utkin

unread,
Dec 7, 2017, 3:44:44 PM12/7/17
to ngrest
You may try to use json parser and the serializer generated with codegen.

include header file matching your interface file + Wrapper.h and use YourStructSerializer::deserialize


// parse
        ngrest::MemPool poolJson;
        ngrest::Node* root = ngrest::json::JsonReader::read(chunk->buffer, &poolJson);
        YourStruct res;
        YourStructSerializer::deserialize(root, res);


look for generated file in
.ngrest/local/build/XXX/codegen/YYYWrapper.h

понедельник, 4 декабря 2017 г., 17:20:01 UTC+3 пользователь Kumar написал:

Kumar

unread,
Dec 8, 2017, 6:08:22 AM12/8/17
to ngrest
Thank you for you help.  it help me lot.

I have another query. I want to generate API document out of my rest services. Basically for client reference what are the params and what is the expected return values.

I have implemented many api, to prepare document manually is time consuming. I am looking some tool to auto generate from existing code base.

Could you please suggest any tool to auto generate.

Thanks.
Reply all
Reply to author
Forward
0 new messages