在下面的代码中,我想使用C#获取Json格式。我尝试了以下代码,我不知道如何设置jsonformat .SO请帮助我解决这个问题。
我已经尝试了下面的C#代码我无法获得准确的格式。所以请帮我解决。
Exact Json:
{
"chart": {
"caption": "Quarterly Sales vs. Profit % in Last Year",
"subcaption": "Product-wise Break-up - Harry's SuperMart",
"xAxisName": "Quarter",
"pYAxisName": "Sales",
"sYAxisName": "Profit %",
"numberPrefix": "$",
"numbersuffix": "M",
"sNumberSuffix": "%",
"sYAxisMaxValue": "25",
"paletteColors": "#5598c3,#2785c3,#31cc77,#1aaf5d,#f45b00",
"baseFontColor": "#333333",
"baseFont": "Helvetica Neue,Arial",
"captionFontSize": "14",
"subcaptionFontSize": "14",
"subcaptionFontBold": "0",
"showBorder": "0",
"bgColor": "#ffffff",
"showShadow": "0",
"canvasBgColor": "#ffffff",
"canvasBorderAlpha": "0",
"divlineAlpha": "100",
"divlineColor": "#999999",
"divlineThickness": "1",
"divLineDashed": "1",
"divLineDashLen": "1",
"usePlotGradientColor": "0",
"showplotborder": "0",
"valueFontColor": "#ffffff",
"placeValuesInside": "1",
"showXAxisLine": "1",
"xAxisLineThickness": "1",
"xAxisLineColor": "#999999",
"showAlternateHGridColor": "0",
"legendBgAlpha": "0",
"legendBorderAlpha": "0",
"legendShadow": "0",
"legendItemFontSize": "10",
"legendItemFontColor": "#666666"
},
"categories": [
{
"category": [
{
"label": "Q1"
},
{
"label": "Q2"
},
{
"label": "Q3"
},
{
"label": "Q4"
}
]
}
],
"dataset": [
{
"dataset": [
{
"seriesname": "Processed Food",
"data": [
{
"value": "30"
},
{
"value": "26"
},
{
"value": "33"
},
{
"value": "31"
}
]
},
{
"seriesname": "Un-Processed Food",
"data": [
{
"value": "21"
},
{
"value": "28"
},
{
"value": "39"
},
{
"value": "41"
}
]
}
]
},
{
"dataset": [
{
"seriesname": "Electronics",
"data": [
{
"value": "27"
},
{
"value": "25"
},
{
"value": "28"
},
{
"value": "26"
}
]
},
{
"seriesname": "Apparels",
"data": [
{
"value": "17"
},
{
"value": "15"
},
{
"value": "18"
},
{
"value": "16"
}
]
}
]
}
],
"lineset": [
{
"seriesname": "Profit %",
"showValues": "0",
"data": [
{
"value": "14"
},
{
"value": "16"
},
{
"value": "15"
},
{
"value": "17"
}
]
}
]
}
C#:
public class Chart
{
public string caption { get; set; }
public string subcaption { get; set; }
public string xAxisName { get; set; }
public string pYAxisName { get; set; }
public string sYAxisName { get; set; }
public string numberPrefix { get; set; }
public string numbersuffix { get; set; }
public string sNumberSuffix { get; set; }
public string sYAxisMaxValue { get; set; }
public string paletteColors { get; set; }
public string baseFontColor { get; set; }
public string baseFont { get; set; }
public string captionFontSize { get; set; }
public string subcaptionFontSize { get; set; }
public string subcaptionFontBold { get; set; }
public string showBorder { get; set; }
public string bgColor { get; set; }
public string showShadow { get; set; }
public string canvasBgColor { get; set; }
public string canvasBorderAlpha { get; set; }
public string divlineAlpha { get; set; }
public string divlineColor { get; set; }
public string divlineThickness { get; set; }
public string divLineDashed { get; set; }
public string divLineDashLen { get; set; }
public string usePlotGradientColor { get; set; }
public string showplotborder { get; set; }
public string valueFontColor { get; set; }
public string placeValuesInside { get; set; }
public string showXAxisLine { get; set; }
public string xAxisLineThickness { get; set; }
public string xAxisLineColor { get; set; }
public string showAlternateHGridColor { get; set; }
public string legendBgAlpha { get; set; }
public string legendBorderAlpha { get; set; }
public string legendShadow { get; set; }
public string legendItemFontSize { get; set; }
public string legendItemFontColor { get; set; }
}
public class Category2
{
public string label { get; set; }
}
public class Category
{
public List<Category2> category { get; set; }
}
public class Datum
{
public string value { get; set; }
}
public class Dataset2
{
public string seriesname { get; set; }
public List<Datum> data { get; set; }
}
public class Dataset
{
public List<Dataset2> dataset { get; set; }
}
public class Datum2
{
public string value { get; set; }
}
public class Lineset
{
public string seriesname { get; set; }
public string showValues { get; set; }
public List<Datum2> data { get; set; }
}
public class RootObject
{
public Chart chart { get; set; }
public List<Category> categories { get; set; }
public List<Dataset> dataset { get; set; }
public List<Lineset> lineset { get; set; }
}
public Chart DD()
{
Chart NewChart = new Chart();
NewChart.caption = "";
NewChart.subcaption = "";
NewChart.xAxisName = "";
NewChart.pYAxisName = "";
NewChart.sYAxisName = "";
NewChart.numberPrefix = "";
NewChart.numbersuffix = "";
NewChart.sNumberSuffix = "";
NewChart.sYAxisMaxValue = "";
NewChart.paletteColors = "";
NewChart.baseFontColor = "";
NewChart.baseFont = "";
NewChart.captionFontSize = "";
NewChart.subcaptionFontSize = "";
NewChart.subcaptionFontBold = "";
NewChart.showBorder = "";
NewChart.bgColor = "";
NewChart.showShadow = "";
NewChart.canvasBgColor = "";
NewChart.canvasBorderAlpha = "";
NewChart.divlineAlpha = "";
NewChart.divlineColor = "";
NewChart.divlineThickness = "";
NewChart.divLineDashed = "";
NewChart.divLineDashLen = "";
NewChart.usePlotGradientColor = "";
NewChart.showplotborder = "";
NewChart.valueFontColor = "";
NewChart.placeValuesInside = "";
NewChart.showXAxisLine = "";
NewChart.xAxisLineThickness = "";
NewChart.xAxisLineColor = "";
NewChart.showAlternateHGridColor = "";
NewChart.legendBgAlpha = "";
NewChart.legendBorderAlpha = "";
NewChart.legendShadow = "";
NewChart.legendItemFontSize = "";
NewChart.legendItemFontColor = "";
return NewChart;
}