怎样从JSON中获取数组键值 10
voidjson_value_free_ex(json_settings*settings,json_value*);json_value*json_object_obj...
void json_value_free_ex(json_settings * settings, json_value *);
json_value *json_object_object_get_e(json_value * p, char *name);
char *json_object_to_json_string_e(json_value * p);
unsigned int json_object_to_json_string_length(json_value * p);
int json_object_get_int_e(json_value * p);
int json_array_get_length(json_value * p);
json_value *json_array_get_object(json_value * p, size_t pos);
char *alloc_str_from_json(const char *json_str, json_value * p);
上面是JSON API
err_t device_data_parse(json_value *jptr, char *name, int *value)
{
json_value *jstr;
json_value *jstr_value;
char *value_str = NULL;
jstr = json_object_object_get_e(jptr, name);
if (NULL != jstr) {
jstr_value = json_object_object_get_e(jstr, "value");
value_str = json_object_to_json_string_e(jstr_value);
*value = atoi(value_str) & 0xffff;
return OK;
} else {
return ERR;
}
}
void down_CMD_deal(void)
{
char *down_cmd {"attrSet":["HeatMode"],"uuid":"7E9779F12767F537F7","HeatMode":{"value":"3"}}
json_value *jptr = json_parse(down_cmd, strlen(down_cmd));
device_data_parse(jptr, "HeatMode", &(virtual_device.HeatMode));//取出heatmode后virtual_device.HeatMode=3
}
我想在"attrSet":["HeatMode"]时才执行device_data_parse(jptr, "HeatMode", &(virtual_device.HeatMode)); 应该怎么做呢? 展开
json_value *json_object_object_get_e(json_value * p, char *name);
char *json_object_to_json_string_e(json_value * p);
unsigned int json_object_to_json_string_length(json_value * p);
int json_object_get_int_e(json_value * p);
int json_array_get_length(json_value * p);
json_value *json_array_get_object(json_value * p, size_t pos);
char *alloc_str_from_json(const char *json_str, json_value * p);
上面是JSON API
err_t device_data_parse(json_value *jptr, char *name, int *value)
{
json_value *jstr;
json_value *jstr_value;
char *value_str = NULL;
jstr = json_object_object_get_e(jptr, name);
if (NULL != jstr) {
jstr_value = json_object_object_get_e(jstr, "value");
value_str = json_object_to_json_string_e(jstr_value);
*value = atoi(value_str) & 0xffff;
return OK;
} else {
return ERR;
}
}
void down_CMD_deal(void)
{
char *down_cmd {"attrSet":["HeatMode"],"uuid":"7E9779F12767F537F7","HeatMode":{"value":"3"}}
json_value *jptr = json_parse(down_cmd, strlen(down_cmd));
device_data_parse(jptr, "HeatMode", &(virtual_device.HeatMode));//取出heatmode后virtual_device.HeatMode=3
}
我想在"attrSet":["HeatMode"]时才执行device_data_parse(jptr, "HeatMode", &(virtual_device.HeatMode)); 应该怎么做呢? 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询