How to build a JsonArray with key using the jansson lib

问题内容:

Example:

{
    ...
    "this": [
        {
            "is an": "example"
        }
    ]
}

What I’ve tried so far:

json_t *json = NULL, *json_test_array = NULL, *json_test = NULL;

json = json_object();
json_test_array = json_array();
json_test = json_object();

...

json_object_set_new(json_test, "is an", json_string("example"));
//how do i put a key on the array if json_array_set() don't have the argument for it   
json_array_append_new(json_test_array, 0, json_test); //no key
json_object_set(json, "this", json_test_array);

How can I achieve this?
Thanks in advance.

问题评论:

    
An array is a unnamed series of elements. Why do you want to have a key? Or if you need keys, why do you want an array? Please extend your example to show more than 1 entry.

原文地址:

https://stackoverflow.com/questions/47756814/how-to-build-a-jsonarray-with-key-using-the-jansson-lib

Tags:, ,

添加评论