I have a JSON text, from a search in Sharepoint 2013, and would like to deserialize it into a list of MyClass. I have a solution using KeyValuePair
var results = item["Cells"]["results"].ToObject<List<KeyValuePair<string, string>>>();
But this method removes date formats etc. Everything ends up as string. Eg. a correct Norwegian date in the JSON file ends up as a quasi Norwenglish date in text.
Edit: I'm using the Newtonsoft.Json library.
Edit: Date format is only part of the problem. The deserializing is the main problem for me.
The JSON and class are simplified for this example. The JSON file can have many records like this so it will end up in a list of objects. Do you have a good solution to deserialize this JSON?
JSON
{
"__metadata": {
"type": "SP.SimpleDataRow"
},
"Cells": {
"results": [
{
"__metadata": {
"type": "SP.KeyValue"
},
"Key": "Id",
"Value": "358553",
"ValueType": "Edm.Int64"
},
{
"__metadata": {
"type": "SP.KeyValue"
},
"Key": "Url",
"Value": "http://somewhere.com",
"ValueType": "Edm.String"
},
{
"__metadata": {
"type": "SP.KeyValue"
},
"Key": "Title",
"Value": "My title",
"ValueType": "Edm.String"
},
{
"__metadata": {
"type": "SP.KeyValue"
},
"Key": "MyDate",
"Value": "2017-09-10T11:10:19Z",
"ValueType": "Edm.DateTime"
}
]
}
}
Class
public class MyClass
{
public int Id { get; set; }
public string Url { get; set; }
public string Title { get; set; }
public DateTime MyDate { get; set; }
}