Daniel Tovisi
Daniel Tovisi

Reputation: 17

"StaticJsonBuffer" was not declared in this scope

I made a web server on a NodeMCU ESP8266 module for sending some information. I can send JSON string's but if I try to make a StaticJsonBuffer I get an error that is not declared but I have it included. ArduinoJson version 6.5.0-beta.

Here's my a part of my code:

void getData(){
  StaticJsonBuffer<200> jsonBuffer;
  JsonObject& root = jsonBuffer.createObject();
  root["Temperature"] = Temperature;
  root["Humidity"] = Humidity;
  String json;
  root.prettyPrintTo(json);
  if(server.hasArg("plain") == false){
    server.send(200, "application/json", json);
    return;
  }

Upvotes: 0

Views: 4121

Answers (2)

vaibhav sharma
vaibhav sharma

Reputation: 172

You can use Dynamic JSON Buffer instead, you don't have to initialize size in it. 6.5.0 is not a stable version. So better use version 5 these are stable version and have all the functions working. Dynamic JSON Buffer is working fine with 6.5.0 beta version.

void getData(){
    DynamicJsonBuffer jsonBuffer;
    JsonObject& root = jsonBuffer.createObject();
    root["Temperature"] = Temperature;
    root["Humidity"] = Humidity;
    String json;
    root.prettyPrintTo(json);
    if(server.hasArg("plain") == false){
        server.send(200, "application/json", json);
        return;
    }

Upvotes: 0

Daniel Tovisi
Daniel Tovisi

Reputation: 17

So I have searched a little bit on the ArduinoJson.org and found out that it is recommended to use ArduinoJson version 5.x. Because versions 6.x is in beta an has some changes and bugs ...

Upvotes: 1

Related Questions