[英]getting null while deserialization json
I am trying to deserialize my web response json to an object, at the time object getting null
after deserialization. 我正在尝试将我的网络响应json反序列化为一个对象,当时反序列化之后对象变为
null
。 This is my code: 这是我的代码:
JSON response: JSON响应:
{
"@odata.context": "https://outlook.office365.com/api/v1.0/$metadata#Me/CalendarView",
"value": [
{
"@odata.id": "https://outlook.office365.com/api/v1.0/Users('sathesh@newtechsolution.onmicrosoft.com')/Events('AAMkADQzMGVmNjZmLWY1YjAtNGFkYS1hODY0LTdiMWZlZjZjYmIwOABGAAAAAAAaluoeH9c2Qq33MvKTCqzgBwD1QTj3IO57QaWZ9MZF6weaAAAAAAENAAD1QTj3IO57QaWZ9MZF6weaAAAAAA0kAAA=')",
"@odata.etag": "W/\"9UE49yDue0GlmfTGResHmgAAAAANag==\"",
"Id": "AAMkADQzMGVmNjZmLWY1YjAtNGFkYS1hODY0LTdiMWZlZjZjYmIwOABGAAAAAAAaluoeH9c2Qq33MvKTCqzgBwD1QTj3IO57QaWZ9MZF6weaAAAAAAENAAD1QTj3IO57QaWZ9MZF6weaAAAAAA0kAAA=",
"ChangeKey": "9UE49yDue0GlmfTGResHmgAAAAANag==",
"Categories": [],
"DateTimeCreated": "2015-05-20T12:03:09.4043813Z",
"DateTimeLastModified": "2015-05-20T12:03:09.5606394Z",
"Subject": "Interview Sample",
"BodyPreview": "Interview For API discussion.",
"Body": {
"ContentType": "HTML",
"Content": "<html>\r\n<head>\r\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\r\n<style type=\"text/css\" style=\"display:none;\"><!-- P {margin-top:0;margin-bottom:0;} --></style>\r\n</head>\r\n<body dir=\"ltr\">\r\n<div id=\"divtagdefaultwrapper\" style=\"font-size:12pt;color:#000000;background-color:#FFFFFF;font-family:Calibri,Arial,Helvetica,sans-serif;\">\r\n<p>Interview For API discussion.<br>\r\n</p>\r\n</div>\r\n</body>\r\n</html>\r\n"
},
"Importance": "Normal",
"HasAttachments": false,
"Start": "2015-05-20T16:00:00Z",
"StartTimeZone": "Sri Lanka Standard Time",
"End": "2015-05-20T17:00:00Z",
"EndTimeZone": "Sri Lanka Standard Time",
"Reminder": 15,
"Location": {
"DisplayName": "Interview Sample Chennai MRC NAGAR",
"Address": { "Street": "", "City": "", "State": "", "CountryOrRegion": "", "PostalCode": "" },
"Coordinates": { "Accuracy": "NaN", "Altitude": "NaN", "AltitudeAccuracy": "NaN", "Latitude": "NaN", "Longitude": "NaN" }
},
"ResponseStatus": { "Response": "Organizer", "Time": "0001-01-01T00:00:00Z" },
"ShowAs": "Busy",
"IsAllDay": false,
"IsCancelled": false,
"IsOrganizer": true,
"ResponseRequested": true,
"Type": "SingleInstance",
"SeriesMasterId": null,
"Attendees": [
{
"EmailAddress": { "Address": "skumar@viswambara.com", "Name": "skumar@viswambara.com" },
"Status": { "Response": "None", "Time": "0001-01-01T00:00:00Z" },
"Type": "Required"
}
],
"Recurrence": null,
"Organizer": {
"EmailAddress": { "Address": "sathesh@newtechsolution.onmicrosoft.com", "Name": "sathesh kumar" }
},
"iCalUId": "040000008200E00074C5B7101A82E0080000000019D340F0F492D0010000000000000000100000005BA1B6261EECD34D991C5BE7D4A70547"
}
]
}
Class: 类:
public class value
{
public string Id { get; set; }
public string ChangeKey { get; set; }
public List<object> Categories { get; set; }
public string DateTimeCreated { get; set; }
public string DateTimeLastModified { get; set; }
public string Subject { get; set; }
public string BodyPreview { get; set; }
public Body Body { get; set; }
public string Importance { get; set; }
public bool HasAttachments { get; set; }
public string Start { get; set; }
public string StartTimeZone { get; set; }
public string End { get; set; }
public string EndTimeZone { get; set; }
public int Reminder { get; set; }
public Location Location { get; set; }
public ResponseStatus ResponseStatus { get; set; }
public string ShowAs { get; set; }
public bool IsAllDay { get; set; }
public bool IsCancelled { get; set; }
public bool IsOrganizer { get; set; }
public bool ResponseRequested { get; set; }
public string Type { get; set; }
public object SeriesMasterId { get; set; }
public List<Attendee> Attendees { get; set; }
public object Recurrence { get; set; }
public Organizer Organizer { get; set; }
public string iCalUId { get; set; }
}
Deserialization: 反序列化:
JavaScriptSerializer json = new JavaScriptSerializer();
value condiiton = (value)json.Deserialize(responcedata, typeof(value));
Let's look at your JSON object. 让我们看一下您的JSON对象。 You actually have an anonymous JSON (let's call it
response
) object with two objects: string '@odata.context' and array 'value' of objects of value
C# class type. 实际上,您有一个带有两个对象的匿名JSON对象(我们称其为
response
):字符串'@ odata.context'和value
C#类类型的对象的数组'value'。
You have described value
class but now you are trying do deserialize response
object to value
which is incorrect. 您已经描述了
value
类,但是现在您尝试将response
对象反序列化为不正确的value
。
You need to describe the corresponding class and deserialize it. 您需要描述相应的类并将其反序列化。
public class Response
{
public value[] value { get; set; }
}
Then you can do it this way: 然后,您可以通过以下方式进行操作:
JavaScriptSerializer json = new JavaScriptSerializer();
Response response = (Response)json.Deserialize(responcedata, typeof(Response));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.