【ArduinoJson 字符串为NULL问题解决】

ArduinoJson 字符串为NULL问题解决

  • 问题现象
  • 产生原因
  • 解决方法:
  • 参考资料:

问题现象

【ArduinoJson 字符串为NULL问题解决】_第1张图片

id是随时变化的,到一定数就会为为null

产生原因

ArduinoJson 在 JsonDocument 中复制String,内存占用完就会null.
【ArduinoJson 字符串为NULL问题解决】_第2张图片

解决方法:

  • 加大jsonDocument的容量 ,因为id要随时变化,并不适用
  • 替换生成的字符串
 String repstr = "{\"id\":\""+String(Send2netDataId)+"\"";  //{"id":"3"  前一段修改

 int index jsonBuf.indexOf(",\"params");  //找到后一段的索引

 jsonBuf = jsonBuf.substring(index);   //提取子串得到后一段

 jsonBuf = repstr+jsonBuf;  

参考资料:

document-contains-null-instead-of-string

你可能感兴趣的:(笔记,c语言,c++,bug)