json-c라이브러리를 설치 및 활용

 

 

json-c/json-c

https://github.com/json-c/json-c is the official code repository for json-c. See the wiki for release tarballs for download. API docs at http://json-c.github.io/json-c/ - json-c/json-c

github.com

 

json-c/json-c

https://github.com/json-c/json-c is the official code repository for json-c. See the wiki for release tarballs for download. API docs at http://json-c.github.io/json-c/ - json-c/json-c

github.com

  • 2. $ cd json-c
  • 3. $ sh autogen.sh
  • 4. $ ./configure
  • 5. $ make
  • 6. $ make install
  • 7. $ make check

 

 

json-c: json.h File Reference

 

json-c.github.io

 

1 CC  = gcc   
2 INC  = -I.   
3 LIBS = -ljson-c   
4 CFLAGS = -O2 -g -Wall ${INC}   
5   
6 json : json.o   
7     $(CC) $(CFLAGS) -o $@ $< $(LIBS)   
8   
9 clean :  
10     rm -f ./json  
11  
12 .SUFFIXES: .o  
13  
14 .c.o :  
15     $(CC) $(CFLAGS) -c $<

Makefile

 

#include<stdio.h>
#include<json.h>

int main(int argc,char **argv) {
json_object *myobj, *dataobj;
         // 메모리 할당
      myobj = json_object_new_object();
      dataobj = json_object_new_object();
      json_object_object_add(dataobj, "test1", json_object_new_int(1));
      json_object_object_add(dataobj, "test2", json_object_new_string("TEST2"));
      json_object_object_add(myobj, "testData", dataobj);
      printf("myobj.to_string()=%s\n", json_object_to_json_string(myobj));
      // 메모리 해제
      json_object_put(dataobj);
      json_object_put(myobj); 
return 0;
}

테스트코드

'기타 > etc' 카테고리의 다른 글

jansson 라이브러리  (0) 2020.06.19
mysql root password 설정방법  (0) 2020.06.12
윈도우10에서 환경변수 등록방법  (0) 2020.05.29

+ Recent posts