8000 How to correct return JsonObject from my custom class? · Issue #827 · bblanchon/ArduinoJson · GitHub
[go: up one dir, main page]

Skip to content
How to correct return JsonObject from my custom class? #827
@VadimShtukan

Description

@VadimShtukan

I cannot correct return JsonObject from my custom class. When I call serializeJson it calls exception. Inside class function serializeJson works correctly.

Error:

Exception (3):
epc1=0x40202d08 epc2=0x00000000 epc3=0x00000000 excvaddr=0x402032a4 depc=0x00000000

ctx: cont 
sp: 3ffffd40 end: 3fffffd0 offset: 01a0

My code:

SMConfigESP.h

#ifndef ARDUINOPROJECTS_CONFIGESP_H
#define ARDUINOPROJECTS_CONFIGESP_H

#include <ArduinoJson.h>

#define CONFIG_JSON_SIZE 200 //Размер json config ----

class SMConfigESP{
public:
    JsonObject buildJson(); 
};

#endif //ARDUINOPROJECTS_CONFIGESP_H

SMConfigESP.cpp

#include "SMConfigESP.h"

SMConfigESP::SMConfigESP() {

}

JsonObject SMConfigESP::buildJson() {
    StaticJsonDocument<CONFIG_JSON_SIZE> jsonDoc;
    JsonObject root = jsonDoc.to<JsonObject>();

    root["sensor"] = "gps";
    root["time"] = 1351824120;

    JsonArray data = root.createNestedArray("data");
    data.add(48.756080);
    data.add(2.302038);
        
    String t;
    //It`s working!!!
    serializeJson(root, t);

    return root;
}

main.ino

#include <ArduinoJson.h>
#include "SMConfigESP.h"

SMConfigESP smConfigESP;

void setup() {
  JsonObject rootJsonConfig = smConfigESP.buildJson();
  
  String t;
  //It throw exception!
  serializeJson(rootJsonConfig, t);
}

void loop() { 
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0