I'm trying to create an array of strings. I'm building each individual string by parsing a json file and getting the strings between '{'s and '}'s. However, for some reason, my array is loosing values and only assigning one index with the string i want. This is my code:
String day = "";
String Combo[] = {"0","0","0","0","0","0","0","0"};
int x = 2;
int number = 0;
/* Read data until either the connection is closed, or the idle timeout is reached. */
unsigned long lastRead = millis();
while (www.connected() && (millis() - lastRead < IDLE_TIMEOUT_MS)) {
/* Reads one character at a time*/
while (www.available()) {
char sym = www.read();
if (sym == '{') {
x = 1;
}
if (x==1){
if (!day.concat(sym)) {
//Serial.println("concat() error!");
}
}
if (x==1 && sym == '}'){
x=0;
Serial.println(number);
}
if ((number > 0) && (number < 9) && (x==0)) {
Combo[number-1] = day;
Serial.print(day);
forCombo[number-1] (int= jday;
= 0; j
< 7; j++) {
Serial.println(F("-------------------------------------"));
Serial.printprintln(Combo[j]Combo[number-1]);
}
Serial.println(F("-------------------------------------"));
Serial.println(F("-------------------------------------"));
day = "";
number +=1;
x = 2;
} else if (number ==0 && x ==0){
day = "";
number +=1;
x = 2;
}
lastRead = millis();
}
}
0{
1 "firstString"
000000 }-------------------------------------
2
-------------------------------------
-------------------------------------
{
"secondString"
"firstString"}-------------------------------------
{
"secondString"
}00000
-------------------------------------
concat() error! ..... concat() error!
3-------------------------------------
{
"firstString""thirdString"
}0000-------------------------------------
concat() error! ..... concat() error!
4-------------------------------------
-------------------------------------
{
"firstString""fourthString"
}000-------------------------------------
concat() error! ..... concat() error!
5-------------------------------------
-------------------------------------
{
"firstString""fifthString"
}00-------------------------------------
concat() error! ..... concat() error!
6-------------------------------------
-------------------------------------
{
"firstString""sixthString"
}0-------------------------------------
concat() error! ..... concat() error!
7-------------------------------------
-------------------------------------
{
"firstString""seventhString"
}-------------------------------------
concat() error! ..... concat() error!
8-------------------------------------
-------------------------------------
{
"eighthString"
"firstString"}-------------------------------------
-------------------------------------
-------------------------------------
{
"secondString"
}-------------------------------------
9
9
9
First, "firstString" is the only stringBased on this output I know that day is being constructed correctly but for some reason isn't assigned to an index (this index changes randomly) in Combo, and second, Combo looses elements (the 00000s decrease every iterationexcept "secondString").
Does Does anyone know what's going on?
Ideally Combo would equal: {"firstString", "secondString""secondString", "thirdString", ... "seventhString""eighthString"}
EDIT: It turns out that "day.concat(sym)" fails sometimes and randomly. Does anyone know why?