본문 바로가기
개발 업무(코딩)-개발자였을때 썼던..

C-JSON EXAMPLE 예제 3 - ARRAY 다른형태

by 주용사 2023. 1. 9.
728x90
/* setting */
json_object *subobj, *taglist_obj, *tag_obj;

subobj = json_object_new_object();
taglist_obj = json_object_new_array();

tag_obj = json_object_new_string("test1");
json_object_array_add(taglist_obj, tag_obj);
tag_obj = json_object_new_string("test2");
json_object_array_add(taglist_obj, tag_obj);

/* merge */
json_object_object_add(subobj, "tag_list", taglist_obj);


/* free */
json_object_put(taglist_obj);
json_object_put(tag_obj);
json_object_put(subobj);
---------------------------------------------------------------

/* output */
"asdfsf" : {     
"tag_list":[ "test1", "test2"]
}

tag_list만 볼 것 나머진 다 약식으로 가라다..

저런식으로 array를 만들어 줄 수 있다.

사실 array로 제목을 정했지만 중요한건

tag_obj = json_object_new_string("test1"); 이고

tag_obj = json_object_new_int(1234); 이런식도 가능하다.

728x90