I am working with C# project in which, most data was of basic type all these days such as string, int, bool. Our client imprlements the JSON with System.Runtime.Serialization.Json, where we deserialize JSON sent from a server that is implemented in C++.
So for instance if I had to De-serialize a JSON sent from the server with 2 string keys such as:
{
"key1":"value1",
"key2":"value2"
}
we would define a class such as
[DataContract]
public class DeserializeKeys
{
[DataMember] public string key1 { get; set; }
[DataMember] public string key2 { get; set; }
};
Our server side code has changed to now send array of strings as a value as shown in the JSON object below:
{
"key1":"value1",
"key2":
[
"arrayValue1",
"arrayValue2",
"arrayValue3"
]
}
Please help me write a corresponding class that can deserialize the given JSON using "System.Runtime.Serialization.Json" class in C#.
I have already tried:
[DataContract]
public class DeserializeKeys
{
[DataMember] public string key1 { get; set; }
[DataMember] public string[] key2 { get; set; }
};
and
[DataContract]
public class DeserializeKeys
{
[DataMember] public string key1 { get; set; }
[DataMember] public List<string> key2 { get; set; }
};
but I am getting null for key2 upon deserialization.
What is the right way to define a class so that the JSON deserialization of array of string happens just as it works currently for a single string.