Yate Community Forum

General Category => Yate users hangout place => Topic started by: ganapathi on October 31, 2018, 03:20:05 PM

Title: JSON Parser help
Post by: ganapathi on October 31, 2018, 03:20:05 PM
Hi,

Can you please help me with the JSON Parser default cpp function to utilize in modules.

Where i want to format JSON String to JSON Object and add/remove key/value on object .



Title: Re: JSON Parser help
Post by: marian on November 02, 2018, 01:10:16 AM
JSON parser is implemented in libyatescript.
You may link your module with it.
Take a look at modules/javascript.cpp on usage.
Title: Re: JSON Parser help
Post by: ganapathi on November 02, 2018, 02:03:06 AM
Yes. I already linked module with libyatescript and trying with javascript reference but don't know how to access it.

Code: [Select]
ObjList* stack;
GenObject* context;
ExpOperation* op = JsParser::parseJSON(text,mutex(),&stack,context);

//May be if empty then empty JSON object
if (!op)
    op = new ExpWrapper(0,"JSON");
ExpEvaluator::pushOne(stack,op);


Above one to parse and create object i think. but didn't find to access json value.
Title: Re: JSON Parser help
Post by: marian on November 02, 2018, 04:39:25 AM
ExpOperation* op = JsParser::parseJSON(text);
op may be a JsArray or JsObject.
Use YOBJECT macro to check it.
I think you can use the params() method of ScriptContext to access parameters.

parseJSON() method was designed to be used in javascript.
It is not easy to use in another context.
Take a look at libs/yscript/yatescript.h: API for scripting objects.