EEVblog Electronics Community Forum

Electronics => Beginners => Topic started by: Vindhyachal.takniki on October 14, 2016, 06:16:14 am

Title: Arduino Json library query; Atmega2560
Post by: Vindhyachal.takniki on October 14, 2016, 06:16:14 am
For JSOn format using this library: https://github.com/bblanchon/ArduinoJson

1. I have defined Json using:
    StaticJsonBuffer<80> jsonBuffer;
    JsonArray& array = jsonBuffer.createArray();

2. Now I keep on using add operator like as below & keep on adding values in array like this:
    array.add("Value");
    array.add(data[0]);

3. After one loop, I want to reinit the Json array index to 0 again. So that when I now add values , it should again start from index 0. How to do that?

4. Second question is how to know how much array size is filled in Json array at any point of time. This will help in case, intiially I will define a large array, now when I keep on adding values in it, in the end I want to know whats its size know. So that I can optimize the size of initially defined Json array.

In the end I have to send this JSON generated string on SIM800 on a known IP address & port number.
Title: Re: Arduino Json library query; Atmega2560
Post by: FreddyVictor on October 14, 2016, 08:17:25 am
Quote
3. After one loop, I want to reinit the Json array index to 0 again. So that when I now add values , it should again start from index 0. How to do that?
maybe try using: removeAt(size_t index)
Quote
4. Second question is how to know how much array size is filled in Json array at any point of time.
maybe keep a count when you add ?

there is some code (https://github.com/bblanchon/ArduinoJson/blob/master/include/ArduinoJson/JsonArray.hpp) at the top of this to get array size in bytes so perhaps could try something like that