如何从服务器响应中提取数据并将其分配给ESP8266的arduino编码中的变量

问题描述

我正在尝试分别从服务器响应中提取数据并将它们分配给不同的变量。 这是我获取数据的功能

//function
String getValue(String data,char separator,int index)
{
  int found = 0;
  int strIndex[] = {0,0};
  int maxIndex = data.length()-1;

  for(int i=0;i<=maxIndex && found<=index;i++){
    if(data.charAt(i)==separator || i==maxIndex){
      found++;
      strIndex[0] = strIndex[1]+1;
      strIndex[1] = (i == maxIndex) ? i+1: i;
      
    }
  }
  String check = found>index ? data.substring(strIndex[0],strIndex[1]) : "";
  return check;
}

我的发票部分和分配部分在下面共享

  Serial.println(status);
  Serial.print("value 1 --->");
  String index0 = getValue(status,',0);
  Serial.println(index0);

  Serial.print("value 2 --->");
  String index1 = getValue(status,1);
  Serial.println(index1);

我的服务器响应是 0,1,

现在我希望我的index0变量的第一个值位于第0个索引,即0 和index1将值保留在第一个索引即1

但是我上面共享的函数能够在第一个索引中获取值,但不能在第0个索引中获取

这是我得到的结果

0,value 1 --->
value 2 --->0,

有人可以帮助我解决这个问题吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...