C#:asp.net 3.5:反序列化JSON-JSON字符串或对象

本文关键字:JSON-JSON 字符串 对象 反序列化 asp net | 更新日期: 2023-09-27 18:28:03

我已经发布了如何在c#中反序列化json,但这是我的问题:

我得到了这个json字符串:

data = @"[{""ShiftID"":""2"",""EmpName"":""dsdsfs""},{""ShiftID"":""4"",""EmpName"":""dsdsfd""}]"; 

我的代码可以完美地反序列化它,但如果我收到这种类型:

data = @"[{
  "Q6Option": null,
  "Q5Comments": "",
  "EndDate": "01/17/2012 12:57",
  "Q4Comments": "",
  "Active": 1,
  "Q3Comments": "",
  "Q8Option": null,
  "Q2Comments": "",
  "StartDate": "01/17/2012 12:57",
  "Q3Option": null,
  "Q5Option": null,
  "Q1Comments": "",
  "Q2Option": null,
  "Station": "B1",
  "Q7Option": null,
  "SyncDate": null,
  "ID": 1,
  "Q8Comments": "",
  "Q4Option": null,
  "ShiftID": 1,
  "EmpName": "CSM FName",
  "Q1Option": null,
  "Q7Comments": "",
  "SyncStatus": 0,
  "Q6Comments": "",
  "EmpID": "111",
  "createdAt": "2012-01-17T20:58:17.956Z",
  "updatedAt": "2012-01-17T20:58:17.956Z",
  "objectId": "XERFM5KrGv"
}]"

它不起作用,因为缺少"。。

如果你有主意,谢谢!

C#:asp.net 3.5:反序列化JSON-JSON字符串或对象

您可以使用.NET framework 3.5 支持的JavaScriptSerializer类

参考链接:

http://msdn.microsoft.com/en-us/library/system.web.script.serialization.javascriptserializer.aspx

示例链接:

http://msdn.microsoft.com/en-us/library/bb412170.aspx

有一些示例json文本与您的问题相同:

{"__type":"Shape:#MyApp.Shapes","x":50,"y":70}