8000 Memory management and deletion of JsonObjects · Issue #153 · nkolban/esp32-snippets · GitHub
[go: up one dir, main page]

Skip to content
Memory management and deletion of JsonObjects #153
Closed
@rickAllDev

Description

@rickAllDev

I'm a bit confused on how to use json class with nested arrays. The following seems to work but I'm not sure its is the correct method. And, is it necessary to delete JsonObject and JsonArray on function complete.

...create json

	JSON json;
	JsonObject obj = json.createObject();
	JsonArray j_array = json.createArray();
    	obj.setInt("name", name);
        for(int i=0; i<num_items; i++) {
        	JsonObject obj1 = json.createObject();
        	obj1.setString("ssid", network.wifi[i].ssid);
        	obj1.setString("pwd", network.wifi[i].pwd);
        	j_array.addObject(obj1);
        }
        obj.setArray("wifi", j_array);

...read json - couldn't  figure out how to do without using m_node
obj = json.parseObject(std::string(str));
    	j_array.m_node = cJSON_GetObjectItem(obj.m_node, "contact");
        for(int i=0; i<j_array.size(); i++) {
        	j_array.getObject(i).getString("name").copy(name, sizeof(name);
        }

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0