Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • A ArduinoJson
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 24
    • Issues 24
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 0
    • Merge requests 0
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Benoît Blanchon
  • ArduinoJson
  • Issues
  • #57
Closed
Open
Issue created Mar 10, 2015 by Administrator@rootContributor

Encoding variable number of nested objects

Created by: orphuz

Hello and thank you for your great work. I use your library for building a multisensor platform (based on an Arduino Mega) for indoor air quality and use JSON for communicating with an handheld device. Your library does quite a job in my project. However I still have one problem for which i just can't find a proper solution.

My idea is generate a variable number of nested object within an iteration. In this iteration I try to assign the values of an array of integers and an corresponding array of chararrays to the key-value pairs of each object. I do understand, that I can't build an array of objects, since the objects are references theirself. But I don't know how to deal with that probelm.

Here is what i want to do in pseudo code:

int iLength_of_list = 3;
int list[3];
list[0] = 5;
list[1] = 7;
list[2] = 1;

StaticJsonBuffer<256> jsonBuffer;
JsonObject& joMessage = jsonBuffer.createObject();
joMessage["length of list"] = iLength_of_list;

/* some magic must happen here, similar to JsonObject& nestedObject[iLength_of_list] */

for (int i = 0; i<= iLength_of_list-1;i++) {
    char cBuffer[2];
    sprintf(cBuffer, "%d", i)
    nestedObject[i] = joMessage.createNestedObject(cBuffer);
    nestedObject[i]["en"] = englishTextOfIndex(list[i]);
    nestedObject[i]["de"] = germanTextOfIndex(list[i]);
}
joMessage.printTo(Serial)

I hope you can get an idea of what I am trying to do. I have read through all the issues and think that franklinvv in issue #10 had a similar problem, but the examplecode does not run for me.

Many thanks in advance

Chris

Assignee
Assign to
Time tracking