{
"IPAuthority":1,
"101":{"data1":
[['2019-8-14 8:00:00', 1], ['2019-8-14 8:10:00', 3], ['2019-8-14 8:20:00', 5], ['2019-8-14 8:30:00', 6], ['2019-8-14 8:40:00', 66],['2019-8-14 8:50:00', 8], ['2019-8-14 9:00:00',11], ['2019-8-14 9:20:00', 32], ['2019-8-14 9:30:00', 54]],
"data2":
[['2019-8-14 8:00:00', 1], ['2019-8-14 8:10:00', 3], ['2019-8-14 8:20:00', 5], ['2019-8-14 8:30:00', 6], ['2019-8-14 8:40:00', 66],['2019-8-14 8:50:00', 8], ['2019-8-14 9:00:00',11], ['2019-8-14 9:20:00', 32], ['2019-8-14 9:30:00', 54]]
},
"102":{"data1":
[['2019-8-14 8:00:00', 1], ['2019-8-14 8:10:00', 3], ['2019-8-14 8:20:00', 5], ['2019-8-14 8:30:00', 6], ['2019-8-14 8:40:00', 66],['2019-8-14 8:50:00', 8], ['2019-8-14 9:00:00',11], ['2019-8-14 9:20:00', 32], ['2019-8-14 9:30:00', 54]],
"data2":
[['2019-8-14 8:00:00', 1], ['2019-8-14 8:10:00', 3], ['2019-8-14 8:20:00', 5], ['2019-8-14 8:30:00', 6], ['2019-8-14 8:40:00', 66],['2019-8-14 8:50:00', 8], ['2019-8-14 9:00:00',11], ['2019-8-14 9:20:00', 32], ['2019-8-14 9:30:00', 54]]
}
}
想生成這樣的格式,讓后類這樣設計:
public class Rootobject
{
public int IPAuthority { get; set; }
public _101 data { get; set; }
public _102 data { get; set; }
}
public class data
{
public Dictionary<string, int> data1 { get; set; }
public Dictionary<string, int> data2 { get; set; }
}
結果生成了
{
"IPAuthority":1,
"101":{"data1":
{'2019-8-14 8:00:00', 1, '2019-8-14 8:10:00', 3, '2019-8-14 8:20:00', 5, '2019-8-14 8:30:00', 6, '2019-8-14 8:40:00', 66,'2019-8-14 8:50:00', 8, '2019-8-14 9:00:00',11, '2019-8-14 9:20:00', 32, '2019-8-14 9:30:00', 54},
.......................
}
類該如何修改
uj5u.com熱心網友回復:
錯了吧。應該類似于(我沒實測過,只是寫個大概)
public class Rootobject
{
public int IPAuthority { get; set; }
//101,102作為key
public Dictionary<string,data> data { get; set; }
}
public class data
{
public List<string> list{get;set;}
}
uj5u.com熱心網友回復:
public class data{
public List<string> list{get;set;}
}
list直接賦值為“'2019-8-14 8:00:00', 1”么?
uj5u.com熱心網友回復:
你這個Json寫法就標準的形式;[['2019-8-14 8:00:00', 1], ['2019-8-14 8:10:00', 3], ['2019-8-14 8:20:00', 5], ['2019-8-14 8:30:00', 6], ['2019-8-14 8:40:00', 66],['2019-8-14 8:50:00', 8], ['2019-8-14 9:00:00',11], ['2019-8-14 9:20:00', 32], ['2019-8-14 9:30:00', 54]]
這段陣列里邊怎么放了一個個陣列?從這個資料來看,應該是:
[{'2019-8-14 8:00:00', 1}, {'2019-8-14 8:10:00', 3}] 這種形式的集合;
具體類結構:
public class Rootobject
{
public int IPAuthority { get; set; }
public Dictionary<string,data> DataArray{ get; set; }
}
public class data
{
public Dictionary<string,List<DataValue>> data1 { get; set; }
public Dictionary<string,List<DataValue>> data2 { get; set; }
}
public class DataValue
{
public string DateTime{get;set;}
public int Age{ get; set;}
}
uj5u.com熱心網友回復:
echarts 的折線,x軸為時間軸的資料格式就是這樣的
[["2020-06-18",5366],["2020-06-19",5395],["2020-06-20",5415],["2020-06-21",5420].......]
uj5u.com熱心網友回復:
恩,那就給上邊最后的物件里邊在來個List<物件>就行了,這個List只存一個資料;
uj5u.com熱心網友回復:
簡化類,這樣設的
public class Rootobject
{
public int IPAuthority { get; set; }
public List<List<string>> Data1 { get; set; } = new List<List<string>>();
}
賦值
...實體化類
foreach (DataRow dr in dt.Rows)
{
rootobject.Data1.Add(new List<string> { (dr["rq"].ToString()+ "," +dr["vv"].ToString() });
}
結果變成這樣了
{"ipAuthority":1,"data1":[["2020-07-01,1341"],["2020-07-02,1346"],["2020-07-03,1347"],["2020-07-04,1348"]]}
還是不符合要求
uj5u.com熱心網友回復:
還有,類中IPAuthority和Data1的首字母都是大寫,生成的json怎么變成首字母小寫了轉載請註明出處,本文鏈接:https://www.uj5u.com/net/17936.html
標籤:ASP.NET
