[英]C# : asp.net 3.5 : Deserialize JSON - json string or object?
i have posted how to deserialize a json in c# but this is my question: 我已经发布了如何在C#中反序列化json,但这是我的问题:
i got this json string : 我得到了这个json字符串:
data = @"[{""ShiftID"":""2"",""EmpName"":""dsdsfs""},{""ShiftID"":""4"",""EmpName"":""dsdsfd""}]";
and my code can deserialize it perfectly but well, if i receive this type : 如果我收到此类型,我的代码可以完美地反序列化它:
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"
}]"
it doesnt work because of there is missing "".. 它不起作用,因为缺少“”。
Well if you have an idea , thanks! 好吧,如果您有个主意,谢谢!
You can use the JavaScriptSerializer class that are supported from .NET framework 3.5 您可以使用.NET Framework 3.5支持的JavaScriptSerializer类
Reference link: 参考链接:
http://msdn.microsoft.com/en-us/library/system.web.script.serialization.javascriptserializer.aspx http://msdn.microsoft.com/zh-CN/library/system.web.script.serialization.javascriptserializer.aspx
Sample link: 样本链接:
http://msdn.microsoft.com/en-us/library/bb412170.aspx http://msdn.microsoft.com/en-us/library/bb412170.aspx
There are some sample json texts that are same as your issue: 有一些示例json文本与您的问题相同:
{"__type":"Shape:#MyApp.Shapes","x":50,"y":70} {“ __type”:“ Shape:#MyApp.Shapes”,“ x”:50,“ y”:70}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.