有时候,数据采集样式各异,其中有些数据生成的json字段层层嵌套,有遇到一个复杂json格式,记录一下
1 { 2 "success": true, 3 "data": [ 4 { 5 "Column": [ 6 { 7 "categories": ["2011", "2012","2013","2014","2015",{"startR": "1","YYY": "1"}], 8 "series": [ 9 { 10 "name": "新成交量3", 11 "data": [1,2,3,4,5] 12 }, 13 { 14 "name": "新成交量3", 15 "data": [1,2,3,4,5] 16 ] 17 }, 18 { 19 "name": "新成交量3", 20 "data": [1,2,3,4,5] 21 } 22 ] 23 } 24 ], 25 "tips": "jkjj" 26 } 27 ] 28 }
public class ALL { public bool success { get; set; } public List<Data> data { get; set; } } public class Data { public List<Column> Column { get; set; } public string tips { get; set; } } public class Column { public List<object> categories { get; set; } public List<Series> series { get; set; } } public class Series { public string name { get; set; } public List<object> data { get; set; } }
public static void test() { try { ALL all = new ALL(); all.success = true; //11111111 all.data = new List<Data>(); Data data = new Data(); data.tips = "jkjj"; //11111111 data.Column = new List<Column>(); Column column = new Column(); column.categories = new List<object>(); column.categories.Add("2011"); column.categories.Add("2012"); column.categories.Add("2013"); column.categories.Add("2014"); column.categories.Add("2015"); var obj = new JObject(); obj.Add("startR", "1"); obj.Add("YYY", "1"); column.categories.Add(obj); column.series = new List<Series>(); Series series = new Series(); series.name = "新成交量3"; series.data = new List<object>(); for (int n = 1; n < 6; n++) { series.data.Add(n); } column.series.Add(series); column.series.Add(series); column.series.Add(series); data.Column.Add(column); all.data.Add(data); String json = JsonConvert.SerializeObject(all, Formatting.Indented); Console.WriteLine(json); Console.Read(); } catch(Exception e) { } }