2. using Newtonsoft.Json;
3. 以 JsonConvert.DeserializeObject 將 string反序列化Json物件成為C#內的物件
在整理成DataTable 後,轉成html
private void parseJson(string json)
{
//ReadFromFile();
RootObject rootObject = JsonConvert.DeserializeObject
int days = rootObject.days;
//MessageBox.Show("共" + days + "筆資料");
DataTable newDt = new DataTable();
newDt.Columns.Add("column1", typeof(string));
newDt.Columns.Add("column2", typeof(string));
newDt.Columns.Add("column3", typeof(string));
newDt.Columns.Add("column4", typeof(string));
newDt.Columns.Add("column5", typeof(string));
int i = 0;
while (++i <= days)
{
newDt.Columns.Add(i.ToString(), typeof(string));
}
//rootObject.aaData.Sort(CompareFloat);
foreach (DataRow row in rootObject.aaData.Rows)
{
//MessageBox.Show(row["id"] + " - " + row["item"]);
if ( !row["score_0"].Equals("100.0000"))
{
DataRow workRow;
workRow = newDt.NewRow();
workRow[0] = row["eDeskId"];
workRow[1] = row["systemName"];
workRow[2] = "";
workRow[3] = row["keySystem"];
for (i = 0; i <= days; i++)
{
string score = row["score_" + i].ToString();
if( score.Equals("100.0000") )
{
workRow[i + 4] = "100";;
}
else
{
redCount++;
workRow[i + 3] = "" + row["score_" + i] + "";
}
}
newDt.Rows.Add(workRow);
}
}
stringHtml = ExportHtml(newDt);
textBox2.Text = stringHtml;
htmlFileName = "qos_" + DateTime.Now.Month + "_" + DateTime.Now.Day + ".html";
StreamWriter sw = new StreamWriter(workDir + @"\" + htmlFileName, true, Encoding.Default);
sw.Write(stringHtml);
sw.Close();
StreamWriter sw2 = new StreamWriter(workDir + @"\redCount.txt", true, Encoding.Default);
sw2.Write(Convert.ToString(redCount));
sw2.Close();
}
沒有留言:
張貼留言