CJSON create.c

 

#include 
#include "cJSON.h"

/*
{
    "semantic": {
        "slots":    {
            "name": "张三"
        }
    },
    "rc":   0,
    "operation":    "CALL",
    "service":  "telephone",
    "text": "打电话给张三"
}

*/
int main()
{
    cJSON * root =  cJSON_CreateObject();
    cJSON * item =  cJSON_CreateObject();
    cJSON * next =  cJSON_CreateObject();

    cJSON_AddItemToObject(root, "rc", cJSON_CreateNumber(0));
    cJSON_AddItemToObject(root, "operation", cJSON_CreateString("CALL"));
    cJSON_AddItemToObject(root, "service", cJSON_CreateString("telephone"));
    cJSON_AddItemToObject(root, "text", cJSON_CreateString("打电话给张三"));
    cJSON_AddItemToObject(root, "semantic", item);
    cJSON_AddItemToObject(item, "slots", next);
    cJSON_AddItemToObject(next, "name", cJSON_CreateString("张三"));

    printf("%s\n", cJSON_Print(root));

    return 0;
}   

 

你可能感兴趣的:(CJSON create.c)