I have the following JSON:
{
"id": "3cf5373c-9181-4639-89f0-bb64b387f961",
"display": "Data 1",
"country": "AU"
}
and I know how to construct the class to serialize it:
[DataContract]
public class myJSONClass
{
[DataMember(Name = "id")]
public string Id { get; set; }
[DataMember(Name = "display")]
public string Display { get; set; }
[DataMember(Name = "country")]
public string Country { get; set; }
}
and I use the below to serialize:
var url = "http://myJSONAPI/";
var syncClient = new WebClient();
var content = syncClient.DownloadString(url);
DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(myJSONClass));
using (var ms = new MemoryStream(Encoding.Unicode.GetBytes(content)))
{
var jsonData = (myJSONClass)serializer.ReadObject(ms);
}
But how would I go about defining my class if my JSON is like the below?
[
{
"id": "3cf5373c-9181-4639-89f0-bb64b387f961",
"display": "My Data 1",
"country": "AU"
},
{
"id": "8886d2c8-0fd5-49ff-a3e1-7cef9e654514",
"display": "no test",
"country": null
}
]
How would like declare my class?
And how do I serialize it? I cannot use JSON.net as I cannot use newer .Net framework.