JAddStringToObject makes the note.add fail completely

Hi All,

I am trying to send a note containing a string variable. However, the JAddStringToObject method only accepts the variable as a const char*.

I have tried doing this:
String cmd_id = “CommandID”;
JAddStringToObject(body, “cmd_id”, cmd_id.c_str());

String cmd_id = “CommandID”;
const char* cmdid2send = cmd_id.c_str();
JAddStringToObject(body, “cmd_id”, cmdid2send );

Both of them just fail. The message is not created.

I am unable to find any examples. How can I add a string variable to a note?

Thanks in advance,


Hi @rlkeith,

Can you send us the error message you’re seeing? The following works fine for me:

String cmd_id = "CommandID";
JAddStringToObject(body, "cmd_id", cmd_id.c_str());

…and I the Note body in Notehub:

Hi Rob,

I just found the cause of the problem. I hooked up the notecard.setDebugOutputStream and found that the notecard was throwing errors over a few characters, especially ¦ (0xA6) and ¶ (0xB6). The string was going into the Notecard with no problem but then it fit as it tried to process them. Those bytes and a few others are produced by the device with which I am interfacing.

I was able to work around the problem but it has taken several hours to work out what was happening. My regular JSON library, Newtonsoft, has worked with those characters for years.