0
我的模型類是在創建JSON結構 -使用JsonConvert.SerializeObject
Details details = new Details();
var info = gets data from service
foreach (var item in info)
{
Points p = new Points();
p.value = item.value;
details.points= new List<Dial>();
fusionChartDetails.points.Add(p);
}
Color c1 = new Color();
c1.code = "#1";
Color c2 = new Color();
c2.code = "#2";
Color c3 = new Color();
c3.code = "#3";
details.colors = new List<Color>();
details.colors.Add(c1);
details.colors.Add(c2);
details.colors.Add(c3);
}
var final=JsonConvert.SerializeObject<details>();
預計:JSON
{
"customer": {
"caption": "Customer 1"
},
"colors": {
"color": [
{
"code": "#1"
},
{
"code": "#2"
},
{
"code": "#3"
}
]
},
"points": {
"point": [
{
"value": "10"
}
]
} }
但是得到這個:
{
"customer": {
"caption": "Customer 1"
},
"colors": [
{
"code": "#1"
},
{
"code": "#2"
},
{
"code": "#3"
}
],
"points": [
{
"value": "10"
}
]
}
不同之處在於內點和顏色對象沒有在我的json結構中被構造。如何做到這一點?
完美!謝謝 – HDev007