File tree Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change 101
101
JsonObject<8> nestedObject;
102
102
array.add(nestedObject);
103
103
104
+ > ##### CAUTION! Nested objects must be in memory
105
+ > Calling ` add() ` makes the ` JsonArray ` store a pointer to the nested object.
106
+ > This is designed to avoid memory duplication.
107
+ > But it can only work if the object is in memory when ` printTo() ` is executed.
108
+ > For instance, don't do this:
109
+ >
110
+ > void addNestedObject()
111
+ > {
112
+ > JsonObject<2> nestedObject;
113
+ > // ...
114
+ > array.add(nestedObject); // <- DON'T !!
115
+ >
116
+ > // array now contains a pointer to a local variable that will be
117
+ > // discarded as soon as the function exits
118
+ > }
119
+ >
120
+ > For the same reason, don't do this either:
121
+ >
122
+ > for( int i=0; i<100; i++)
123
+ > {
124
+ > JsonObject<2> nestedObject;
125
+ > // ...
126
+ > array.add(nestedObject); // <- DON'T !!
127
+ > }
128
+ > // array now contains 100 pointers to the same a local variable
129
+ > // that is out of the scope anyway
130
+
104
131
#### JSON Object
105
132
106
133
You create a JSON object (ie hash-table/dictionary) with the following line:
You can’t perform that action at this time.
0 commit comments