I need to create a list like List<String,Object> but I can't seem to do this.
I created a class:
public class Pair
{
public String Key { get; set; }
public Object Value { get; set; }
}
If I make a List<Pair>, my problem starts when I have to serialize it into JSON , I get something like:
{
"Key": "version",
"Value": "3.2.1"
},
{
"Key": "name",
"Value": "coordinateOperations"
}
While I am expecting:
{
"version": "3.2.1"
},
{
"name": "coordinateOperations"
}
My guess is I have to either find a way to have List<String,Object> or control the serialization mechanism. The latter looks tougher and seems more like a trick rather than a real solution.
Also, I can't have a Dictionary<String,Object> since I will have repeated keys. Maybe a lookup is more needed.
Why create your own? you can use KeyValuePair
List<KeyValuePair<String, Object>> nList = new List<KeyValuePair<String, Object>>();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With