Page 1 of 1

getString in Preference not working

Posted: Thu Aug 29, 2019 4:23 pm
by catotonic
I am trying to interact between ArduinoJson and Preferences.h and ESP32WebServer. For reasons too long to go into for this question, I would like to use the getString method in Preferences.h with the following signature:
size_t getString(const char* key, char* value, size_t maxLen);
I have tried many iterations but cannot figure out how to get the method to accept my parameters, including (size_t)197 and size_t s=197;
Image
Rather than waste everyone's time showing all the things I tried, which didn't work, can someone tell me what I should do or if they have the same problem?
Thanks

Re: getString in Preference not working

Posted: Thu Aug 29, 2019 5:21 pm
by lbernstone
You don't show where you define jCharArray, but it is an array of char pointers. The first overload of getString wants just a char pointer, or else an array which it will cast to a pointer. The (much simpler) second overload will return a String, and just needs the key name. Try just calling String jString = prefs.getString("sparams"); and then convert that to a char array with jString.c_str() where needed.