I finally got all my parsing working with one exception.
the following code works exactly as it should
public void GetCurrentSchedule()
{
String JSONstring = File.ReadAllText("\\USER\\Schedule\\Schedule.txt");
RootObject p1 = JsonConvert.DeserializeObject<RootObject>(JSONstring);
for (int a = i; a <= (i + 3); a++)
{
sDay = p1.schedulePeriods[a].day;
sPeriod = p1.schedulePeriods[a].periodType;
sStart = p1.schedulePeriods[a].startTime;
sCancel= p1.schedulePeriods[a].isCancelled;
sHeat = p1.schedulePeriods[a].heatSetpoint;
sCool = p1.schedulePeriods[a].coolSetpoint;
sFan = p1.schedulePeriods[a].fanMode;
Console.PrintLine("day: {0}", sDay);
Console.PrintLine("period: {0}", sPeriod);
Console.PrintLine("start: {0}", sStart);
Console.PrintLine("Cancel: {0}", sCancel);
Console.PrintLine("Heat: {0}", sHeat);
Console.PrintLine("Cool: {0}", sCool);
Console.PrintLine("Fan: {0}", sFan);
}
}
however what i want to do is assign each pass to array to be called later by index number.
for example
sDay = p1.schedulePeriods[a].day;
i want to have 4 indexes of sDay that i can call by index number from another class.
I have been beating my head against the wall trying to get this working.
Any ideas?
I believe you want something like this?
public void GetCurrentSchedule()
{
String JSONstring = File.ReadAllText("\\USER\\Schedule\\Schedule.txt");
RootObject p1 = JsonConvert.DeserializeObject<RootObject>(JSONstring);
string[] sDay = new string[i + 4];//Declare your array here (+4 becuase your for loop goes upto +3)
for (int a = i; a <= (i + 3); a++)
{
sDay[a - i] = p1.schedulePeriods[a].day; // assign the value to array element (a - i because if i > 0 because arrays start with 0)
sPeriod = p1.schedulePeriods[a].periodType;
sStart = p1.schedulePeriods[a].startTime;
sCancel= p1.schedulePeriods[a].isCancelled;
sHeat = p1.schedulePeriods[a].heatSetpoint;
sCool = p1.schedulePeriods[a].coolSetpoint;
sFan = p1.schedulePeriods[a].fanMode;
Console.PrintLine("day: {0}", sDay[a - i]); // Call it with index
Console.PrintLine("period: {0}", sPeriod);
Console.PrintLine("start: {0}", sStart);
Console.PrintLine("Cancel: {0}", sCancel);
Console.PrintLine("Heat: {0}", sHeat);
Console.PrintLine("Cool: {0}", sCool);
Console.PrintLine("Fan: {0}", sFan);
}
}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments