ESP/HTML 字符串为 11 个或更多字符时的无效字符

ESP/HTML invalid characters when string is 11 characters or more

所以我的问题正如标题所说,我的 html 页面无法显示包含 11 个或更多字符的字符串,它们显示为 - L1�?,我不知道字符串没有使用任何特殊字符并且仅由英文字母组成的问题是什么,如果字符串长度为 11 个字符或更多,可能会导致此问题?这是代码:

server.on("/", HTTP_GET, [] (AsyncWebServerRequest *request) {

  AsyncResponseStream *response = request->beginResponseStream("text/html");

  response->print("<!DOCTYPE html><html><head>");
  response->print("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\"><style>body{background-color: #92a8d1;}</style></head><body>");
  response->print("<img src=\"0\" width=\"100\" height=\"100\">");
  for (int i = 0; i < n; ++i){
    response->printf("<p>%d: %s (%s)%s<br>", i+1, first[i], second[i], third[i]);
  }
  response->printf(" <embed type=\"text/html\" src=\"textplaceholder\"> "); 
  response->print("</body></html>");
  request->send(response);
});

我尝试使用utf-8字符集,但没有解决问题。第 9 行是我将字符串发送到网络服务器的地方,first[i] 是字符串,它也可以超过 11 个字符,因此一些字符串显示正确,而太长的字符串显示为 - L1。 .

感谢任何帮助!

问题是 %s printf 需要 const char * 值,添加 .c_str());到字符串变量的末尾解决了问题。