c/c++使用json

来源:互联网 发布:注册账号的软件 编辑:程序博客网 时间:2024/05/17 00:14

1. JSON_parser 只是对json语法的解析, 是基于sax的. 用于学习挺好的.
2. mjson 同时有dom和sax的完整解析方案, 很不错.
3. tinyjson是基于boost库的解析器, 用于学习挺好的.
4. json-c使用autoconfig兼容性最好,移植是个问题.

 

最后选择mjson.

修改json.h

//#include <stdint.h>

 

 

typedef __int64 int64_t;

typedef unsigned __int64 uint64_t;

 

 

例子(好像部分有问题):

http://mjson.sourceforge.net/examples.html

 

 

#include <stdio.h>

#include <stdlib.h>

#include <locale.h>

#include "json.h"

 

int _tmain(int argc, _TCHAR* argv[])

{

setlocale (LC_ALL, "");

char *document = "{/"entry/":{/"name/":/"Andew/",/"phone/":/"555 123 456/"}}";

 

json_t *root = NULL;

printf("Parsing the document.../n");

 

json_parse_document(&root, document);

 

printf("Printing the document tree.../n");

json_tree_to_string(root, &document);

 

printf("%s/n", document);    

json_free_value(&root);

 

free(document);

 

return EXIT_SUCCESS;

}

 

 

 

原创粉丝点击