色婷婷狠狠18禁久久YY,CHINESE性内射高清国产,国产女人18毛片水真多1,国产AV在线观看

c 遍歷json 慢

c語言是一種高效的編程語言,但是在處理json遍歷時(shí)卻顯得相對(duì)較慢。

#include <stdio.h>
#include <string.h>
#include <jansson.h>
int main()
{
char *json_data = "{\"name\":\"tom\",\"age\":18,\"weight\":65.5,\"hobby\":[\"music\",\"movie\"]}";
json_t *root = NULL;
json_error_t error;
root = json_loads(json_data,0,&error);
if(!root)
{
printf("error:%s\n",error.text);
return -1;
}
json_t *name = json_object_get(root,"name");
const char *name_str = json_string_value(name);
printf("name:%s\n",name_str);
json_t *age = json_object_get(root,"age");
int age_int = json_integer_value(age);
printf("age:%d\n",age_int);
json_t *weight = json_object_get(root,"weight");
double weight_double = json_real_value(weight);
printf("weight:%.1f\n",weight_double);
json_t *hobby = json_object_get(root,"hobby");
if(!json_is_array(hobby))
{
printf("hobby is not array\n");
return -1;
}
int hobby_count = json_array_size(hobby);
int i;
for(i=0;i

如上代碼所示,使用json-c庫解析json數(shù)據(jù),遍歷json數(shù)據(jù)需要先進(jìn)行類型判斷,然后根據(jù)類型進(jìn)行操作,if和for語句也會(huì)造成程序運(yùn)行的緩慢。

相比其他編程語言而言,c語言處理json遍歷會(huì)相對(duì)較慢。