尝试解析 JSON 响应时出错
try
{
var result = (new JavaScriptSerializer()).Deserialize<Rootobject>(jsonResponse);
}
catch(Exception ex){}
JSON字符串
"[{\"ID\":1,\"Code\":null,\"Name\":\"Black\"},{\"ID\":1,\"Code\":null,\"Name\":\"Red\"},{\"ID\":1,\"Code\":\"blx\",\"Name\":\"Blue\"}]"
附有错误详细信息和准确 JSON 字符串的屏幕截图
我正在使用以下代码生成 JSON
public string JSONTest()
{
List<Color> colors = new List<Color>();
colors.Add(new Color() { ID = 1, Name = "Black" });
colors.Add(new Color() { ID = 1, Name = "Red" });
colors.Add(new Color() { ID = 1, Name = "Blue", Code = "blx" });
return JsonConvert.SerializeObject(colors);
}