-2

I'm having a problem extracting the Object/Array from this sample json [ { "sensor":"gps1", "time":1351824120 }, { "sensor":"gps1", "time":1351824120 } ]

Would anyone have some pointers or sample code to allow me to extract the 'time' from each of the objects ?

Thanks

closed as unclear what you're asking by gre_gor, per1234, MatsK, user31481, KIIV Nov 30 '17 at 8:18

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • Check the library examples? – gre_gor Nov 30 '17 at 0:48
  • 1
    What have you tried? Post the code. Tell us in what way it doesn't work, such as error messages on compile, or unexpected response/behaviour. – jose can u c Nov 30 '17 at 1:45
1

You can use the ArduinoJson Assistant on arduinojson.org to create a skeleton.

Here is what it generates in your case:

const size_t bufferSize = JSON_ARRAY_SIZE(2) + 2*JSON_OBJECT_SIZE(2) + 70;
DynamicJsonBuffer jsonBuffer(bufferSize);

const char* json = "[{\"sensor\":\"gps1\",\"time\":1351824120},{\"sensor\":\"gps1\",\"time\":1351824120}]";

JsonArray& root = jsonBuffer.parseArray(json);

const char* root_0_sensor = root[0]["sensor"]; // "gps1"
long root_0_time = root[0]["time"]; // 1351824120

const char* root_1_sensor = root[1]["sensor"]; // "gps1"
long root_1_time = root[1]["time"]; // 1351824120
  • Thanks, that worked perfectly. Great library and website to help building the code. – AlanR Dec 1 '17 at 11:34

Not the answer you're looking for? Browse other questions tagged or ask your own question.