ArduinoJson set object as string - proper way?

See code. When I Serial print the datetime it looks fine.

But when I attempt to put it into the JSON document and POST it to a webservice, it comes out looking like this: 44718.42256


#include "time.h"

String returnTime();
{
  getLocalTime(&timeinfo);
  char timeStringBuff[50];
  strftime(timeStringBuff, sizeof(timeStringBuff), "%D %H:%M:%S", &timeinfo);
  return timeStringBuff;
}

String datetime;
datetime = returnTime();
Serial.println(datetime);    // This prints the date time properly
StaticJsonDocument<200> doc;
doc[String("timestamp")] = datetime;
String requestBody;
serializeJson(doc, requestBody);
int httpResponseCode = http.POST(requestBody);   // this is where the document gets POST'd

I resolved this by using version 6.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.