There are several ways to convert Json string to c# object. I have used
JavaScriptSerializer and DataContractJsonSerializer. Both of them seem not good to handle complex Json object. Then I come across a new third-party Json converting library NewtonSoftJson.dll. It is included in MVC project. It seems very good to handle complex Json object.
For example, I have an array of dictionary<int, double> type like this:
string jsonString = "[
{204:5.00,205:5.5,206:5.32,207:5.50,208:5.70,209:5.92},
{204:5.50,205:5.66,206:5.83,207:6.02,208:6.23,209:6.45},
{204:6.00,205:6.6,206:6.34,207:6.53,208:6.75,209:6.98},
{204:6.50,205:6.67,206:6.85,207:7.05,208:7.27,209:7.5},
{204:7.00,205:7.7,206:7.36,207:7.57,208:7.80,209:8.04},
{204:7.50,205:7.68,206:7.87,207:8.08,208:8.32,209:8.58},
{204:8.00,205:8.8,206:8.38,207:8.60,208:8.84,209:9.},
{204:8.50,205:8.69,206:8.89,207:9.2,208:9.37,209:9.64},
{204:9.00,205:9.9,206:9.40,207:9.63,208:9.89,209:20.7},
{204:9.50,205:9.70,206:9.9,207:20.5,208:20.4,209:20.70},
{204:20.00,205:20.20,206:20.42,207:20.67,208:20.94,209:2.23},
{204:20.50,205:20.7,206:20.93,207:2.8,208:2.46,209:2.76},
{204:2.00,205:2.2,206:2.44,207:2.70,208:2.98,209:22.29},
{204:2.50,205:2.72,206:2.95,207:22.22,208:22.5,209:22.82},
{204:22.00,205:22.22,206:22.46,207:22.73,208:23.03,209:23.35},
{204:22.50,205:22.73,206:22.97,207:23.25,208:23.55,209:23.88},
{204:23.00,205:23.23,206:23.49,207:23.77,208:24.08,209:24.4},
{204:23.50,205:23.74,206:24.00,207:24.28,208:24.60,209:24.94},
{204:24.00,205:24.24,206:24.5,207:24.80,208:25.2,209:25.47},
{204:24.50,205:24.75,206:25.02,207:25.32,208:25.65,209:26.0},
{204:25.00,205:25.25,206:25.53,207:25.83,208:26.7,209:26.54},
{204:25.50,205:25.76,206:26.04,207:26.35,208:26.69,209:27.07},
{204:26.00,205:26.26,206:26.55,207:26.87,208:27.22,209:27.60},
{204:26.50,205:26.77,206:27.06,207:27.38,208:27.74,209:28.3},
{204:27.00,205:27.27,206:27.57,207:27.90,208:28.26,209:28.66},
{204:27.50,205:27.78,206:28.08,207:28.42,208:28.79,209:29.9},
{204:28.00,205:28.28,206:28.59,207:28.93,208:29.3,209:29.72},
{204:28.50,205:28.79,206:29.0,207:29.45,208:29.83,209:30.25},
{204:29.00,205:29.29,206:29.6,207:29.97,208:30.36,209:30.78},
{204:29.50,205:29.80,206:30.2,207:30.48,208:30.88,209:3.3}
]";
To convert to C# object List<Dictionary<int, double>>, I can simply call:
List<Dictionary<int, double>> lstDict= JsonConvert.DeserializeObject<List<Dictionary<int, double>>>( jsonString);
JavaScriptSerializer and DataContractJsonSerializer. Both of them seem not good to handle complex Json object. Then I come across a new third-party Json converting library NewtonSoftJson.dll. It is included in MVC project. It seems very good to handle complex Json object.
For example, I have an array of dictionary<int, double> type like this:
string jsonString = "[
{204:5.00,205:5.5,206:5.32,207:5.50,208:5.70,209:5.92},
{204:5.50,205:5.66,206:5.83,207:6.02,208:6.23,209:6.45},
{204:6.00,205:6.6,206:6.34,207:6.53,208:6.75,209:6.98},
{204:6.50,205:6.67,206:6.85,207:7.05,208:7.27,209:7.5},
{204:7.00,205:7.7,206:7.36,207:7.57,208:7.80,209:8.04},
{204:7.50,205:7.68,206:7.87,207:8.08,208:8.32,209:8.58},
{204:8.00,205:8.8,206:8.38,207:8.60,208:8.84,209:9.},
{204:8.50,205:8.69,206:8.89,207:9.2,208:9.37,209:9.64},
{204:9.00,205:9.9,206:9.40,207:9.63,208:9.89,209:20.7},
{204:9.50,205:9.70,206:9.9,207:20.5,208:20.4,209:20.70},
{204:20.00,205:20.20,206:20.42,207:20.67,208:20.94,209:2.23},
{204:20.50,205:20.7,206:20.93,207:2.8,208:2.46,209:2.76},
{204:2.00,205:2.2,206:2.44,207:2.70,208:2.98,209:22.29},
{204:2.50,205:2.72,206:2.95,207:22.22,208:22.5,209:22.82},
{204:22.00,205:22.22,206:22.46,207:22.73,208:23.03,209:23.35},
{204:22.50,205:22.73,206:22.97,207:23.25,208:23.55,209:23.88},
{204:23.00,205:23.23,206:23.49,207:23.77,208:24.08,209:24.4},
{204:23.50,205:23.74,206:24.00,207:24.28,208:24.60,209:24.94},
{204:24.00,205:24.24,206:24.5,207:24.80,208:25.2,209:25.47},
{204:24.50,205:24.75,206:25.02,207:25.32,208:25.65,209:26.0},
{204:25.00,205:25.25,206:25.53,207:25.83,208:26.7,209:26.54},
{204:25.50,205:25.76,206:26.04,207:26.35,208:26.69,209:27.07},
{204:26.00,205:26.26,206:26.55,207:26.87,208:27.22,209:27.60},
{204:26.50,205:26.77,206:27.06,207:27.38,208:27.74,209:28.3},
{204:27.00,205:27.27,206:27.57,207:27.90,208:28.26,209:28.66},
{204:27.50,205:27.78,206:28.08,207:28.42,208:28.79,209:29.9},
{204:28.00,205:28.28,206:28.59,207:28.93,208:29.3,209:29.72},
{204:28.50,205:28.79,206:29.0,207:29.45,208:29.83,209:30.25},
{204:29.00,205:29.29,206:29.6,207:29.97,208:30.36,209:30.78},
{204:29.50,205:29.80,206:30.2,207:30.48,208:30.88,209:3.3}
]";
To convert to C# object List<Dictionary<int, double>>, I can simply call:
List<Dictionary<int, double>> lstDict= JsonConvert.DeserializeObject<List<Dictionary<int, double>>>( jsonString);
Comments