Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

9
  • Your function create a local variable and return it value at end of the function, a local variable will out of Scope upon exiting the function and no longer available. Furthermore, String object uses dynamic memory allocation in the heap, and get free up when it is out of scope. Read a book about C++ programming and try not to use String object if you are new to Arduino/C++ programming. Commented Dec 9, 2020 at 23:52
  • @hcheung sir how can fix this, what should i do to fix this problem. Commented Dec 10, 2020 at 8:37
  • @hcheung: The function returns a String, and that return value is used and present, according to the OP. Variable scope has nothing to do with it. Commented Dec 10, 2020 at 19:33
  • @ocrdu the function works and returns string, i output it using serial print. It is correct. But when i assign it to doc["rfid"], the in the json output the field is null. I created a string to test String a = "example" i assign it to the doc["rfid"] , in the json i show this value it works well with other strings. Commented Dec 10, 2020 at 19:42
  • 1
    So maybe ArduinoJson doesn't play nice with String objects, or there is some other reason I don't know about. I'll write an answer based on my comment; please accept it (if you accept it 8-). Commented Dec 10, 2020 at 20:09