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
  • #827
Closed
Open
Issue created Oct 12, 2018 by Administrator@rootContributor

How to correct return JsonObject from my custom class?

Created by: 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() { 
}
Assignee
Assign to
Time tracking