Yes, that was derp from my end.
Any clue on how to encode the JSON structure I mentioned ?
Is this method correct ?
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 <[email protected]> wrote:
>
> Hi Aditya,
>
>> On Feb 28, 2018, at 9:26 AM, Aditya Xavier <[email protected]> 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.
>