> On Feb 28, 2018, at 10:10 AM, Aditya Xavier <adityaxav...@me.com> wrote:
> 
> Yes, that was derp from my end.
> 
> Any clue on how to encode the JSON structure I mentioned ?
> 
> Is this method correct ?

You need to initialize the encoder; it needs to be told where to write
the encoded data. Specifically, you need to at least fill in je_write
function pointer. This is who’ll get the stream of encoded data.

Take a look at unit test @ encoding/json/test/src/testcases/json_simple_encode.c

Otherwise it looks pretty good, based on my cursory inspection.

> 
>       struct json_encoder *encoder, *module;
>       struct json_value data;
> 
>       memset(&encoder, 0, sizeof(encoder));
>       memset(&module, 0, sizeof(module));
> 
>       json_encode_object_start(encoder);
> 
>       JSON_VALUE_INT(&data, 1);
>       json_encode_object_entry(encoder, “name1", &data);
> 
>       JSON_VALUE_STRING(&data, “value2");
>       json_encode_object_entry(encoder, “name2", &data);
> 
>       json_encode_array_name(encoder, “name3");
>       json_encode_array_start(encoder);
> 
>       if(getType){
>               json_encode_object_start(module);
>       
>               JSON_VALUE_INT(&data, 4);
>               json_encode_object_entry(module, “name4", &data);
> 
>               JSON_VALUE_INT(&data, 5);
>               json_encode_object_entry(module, “name5", &data);
>       
>               json_encode_object_finish(module);
>       }
>       
>       json_encode_array_finish(encoder);
>       json_encode_object_finish(encoder);
> 
> 
> 
>> On 28-Feb-2018, at 1:18 PM, marko kiiskila <ma...@runtime.io> wrote:
>> 
>> Hi Aditya,
>> 
>>> On Feb 28, 2018, at 9:26 AM, Aditya Xavier <adityaxav...@me.com> wrote:
>>> 
>>> HI Mynewt Team,
>>> 
>>>     Wanted some assistance on how to encode and decode the following JSON 
>>> string.
>>> 
>>>     {“name1":1,”name2”:"value2”,"name3":[{“name4":1,”name5":5}]}
>>> 
>>>     Because of sparse documentation, I used the Test sample; however am 
>>> stuck with encoding an array of objects.
>>> 
>> 
>> …
>> 
>>> 
>>>     I followed the example provided at 
>>> https://mynewt.apache.org/latest/os/modules/json/json_encode_object_entry 
>>> <https://mynewt.apache.org/latest/os/modules/json/json_encode_object_entry>
>>> 
>>>     And it gives me error :-
>>>     error: implicit declaration of function 'json_encode_object_start'
>>> 
>>> Thanks,
>>> Aditya Xavier.
>> 
>> you need to #include <json/json.h> to see function/macro declarations.
>> 
> 

Reply via email to