2014年02月05日 星期三 21:48
libU是一组开源免费(BSD-style license)的C语言工具库,代码精巧,运行效率也不错,可以灵活的用于C、C++项目中。其包含JSON的编码解码库,API非常有意思,请参考如下代码示例。
#include <u/libu.h>
#include <stdio.h>
int facility=LOG_LOCAL0;
int main(int argc,char **argv) {
int rt;
char *jsonstr="[100,200,\"mengguang\", \
[1,2,3],{\"age\":30}]";
u_json_t *pjo=NULL;
u_json_decode(jsonstr,&pjo);
u_json_index(pjo);
long l;
u_json_cache_get_int(pjo,".[0]",&l);
printf("l = %ld\n",l);
const char *s=u_json_cache_get_val(pjo,".[2]");
printf("s = %s\n",s);
u_json_cache_get_int(pjo,".[3][2]",&l);
printf("l = %ld\n",l);
u_json_cache_get_int(pjo,".[4].age",&l);
printf("l = %ld\n",l);
u_json_unindex(pjo);
u_json_free(pjo);
return 0;
}
libU的安装指南请参考:
http://www.koanlogic.com/libu/api/html/install.html
libU的JSON API文档请参考:
Zeuux © 2025
京ICP备05028076号