8000 Garabage data at first name in JsonObject,for returned JsonObject from class member function · Issue #785 · bblanchon/ArduinoJson · GitHub
[go: up one dir, main page]

Skip to content
Garabage data at first name in JsonObject,for returned JsonObject from class member function #785
Closed
@pulkit-jain

Description

@pulkit-jain

Hi all

JsonObject& GetJsonRoot() {
File lConfigFile = SPIFFS.open(CONFIG_FILE_PATH, "r");
DynamicJsonBuffer lJsonBuffer;
JsonObject* lJsonRoot = NULL;
if (!lConfigFile) {
Serial.println("Failed to open config file");
return *lJsonRoot;
}

size_t lFileSize = lConfigFile.size();

std::unique_ptr<char[]> lFileData(new char[lFileSize]);
lConfigFile.readBytes(lFileData.get(), lFileSize);

lConfigFile.close();

 lJsonRoot = &lJsonBuffer.parseObject(lFileData.get());

if (!lJsonRoot->success()) {
	Serial.println("Failed to parse config file");
	return *lJsonRoot;
}
lJsonRoot->printTo(Serial);
return *lJsonRoot;

}

Actually when i print lJsonRoot just at the end of GetJsonRoot,it is giving correct data.
But when i print the in the caller method it is giving garbage data for only first name of data.

Correct Data:-{"serverName":"api.example.com","accessToken":"128du9as8du12eoue8da98h123ueh9h98"}
Incorrect Data:- {"⸮�":"api.example.com","accessToken":"128du9as8du12eoue8da98h123ueh9h98"}

Thanks in advance for the help.

Kind Regards
Pulkit Jain

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