[SR-Users] json module / quotes in result
Ron McLeod
ron-bulk at mcleodnet.com
Fri Sep 13 21:22:46 CEST 2013
I changed the modules/json/json_funcs.c to work-around this issue. It is
not complete, as it only handles string and int json types:
int json_get_field(struct sip_msg* msg, char* json, char* field, char* dst)
{
str json_s;
str field_s;
pv_spec_t *dst_pv;
pv_value_t dst_val;
if (fixup_get_svalue(msg, (gparam_p)json, &json_s) != 0) {
LM_ERR("cannot get json string value\n");
return -1;
}
if (fixup_get_svalue(msg, (gparam_p)field, &field_s) != 0) {
LM_ERR("cannot get field string value\n");
return -1;
}
dst_pv = (pv_spec_t *)dst;
struct json_object *j = json_tokener_parse(json_s.s);
enum json_type type = json_object_get_type(json_object_object_get(j,
field_s.s));;
if (type == json_type_string) {
char *value =
(char*)json_object_get_string(json_object_object_get(j, field_s.s));
dst_val.rs.s = value;
dst_val.rs.len = strlen(value);
dst_val.flags = PV_VAL_STR;
}
else if (type == json_type_int) {
int value = json_object_get_int(json_object_object_get(j,
field_s.s));
dst_val.rs.s = '\0';
dst_val.rs.len = 0;
dst_val.ri = value;
dst_val.flags = PV_TYPE_INT|PV_VAL_INT;
}
dst_pv->setf(msg, &dst_pv->pvp, (int)EQ_T, &dst_val);
return 1;
}
Ron
-----Original Message-----
From: sr-users-bounces at lists.sip-router.org
[mailto:sr-users-bounces at lists.sip-router.org] On Behalf Of Florian Lohoff
Sent: September-13-13 10:00 AM
To: sr-users at lists.sip-router.org
Subject: [SR-Users] json module / quotes in result
Hi,
is it correct that the json_get_field returns the quotes from the json
document?
Example:
{ "foo": "bar" }
json_get_field("$var(json)", "foo", "$var(result)");
result will contain "bar" with quotes ...
I was a little astonished to see that.
Flo
--
Florian Lohoff f at zz.de
More information about the sr-users
mailing list