[SR-Users] Question about parsing a jsonrpc_exec result with a colon in object name with jansson_get

jenus at cyberchaos.nl jenus at cyberchaos.nl
Thu Dec 7 13:05:28 CET 2017


Already found the solution. "registrar:accepted_regs = 1" is a string 
and not a json object.

Thanks,

Jan

jenus at cyberchaos.nl schreef op 2017-12-07 10:27:
> Hi all,
> 
> I'm trying to parse the result of a json rpc call to get the register
> statistics.
> 
> 
> # Get registrar stats
> jsonrpc_exec('{"jsonrpc": "2.0", "method": "stats.get_statistics",
> "params": ["accepted_regs"], "id": 1}');
> jansson_get("result[0]", $jsonrpl(body), "$var(registrar_accepted)");
> xlog("LOG_LOCAL3","L_WARN","$jsonrpl(body)\n");
> 
> The $jsonrpl(body) var contains:
> {"jsonrpc":"2.0","result":["registrar:accepted_regs = 2"],"id":1}
> 
> 
> With this code the result stored in $var(registrar_accepted) is :
> "AcceptedRegistrations":"registrar:accepted_regs = 1"
> 
> I'm trying to get only the value. I have tried:
> 
> jansson_get("result[0].registrar:accepted_regs", $jsonrpl(body),
> "$var(registrar_accepted)");
> jansson_get("result[0].['registrar:accepted_regs']", $jsonrpl(body),
> "$var(registrar_accepted)");
> jansson_get("result[0]['registrar:accepted_regs']", $jsonrpl(body),
> "$var(registrar_accepted)");
> 
> But this does not work. Do i need to escape the colon in the object
> name "registrar:accepted_regs" ?
> 
> Thanks,
> 
> Jan
> 
> _______________________________________________
> Kamailio (SER) - Users Mailing List
> sr-users at lists.kamailio.org
> https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users




More information about the sr-users mailing list