0

I have a JSON object with this structure:

{
    "customLineItemParameters": [
    {"paramName1": "value1"}, 
    {"paramName2": "value2"}, 
    {"paramName3": "value3"}
    ]
}

My model property looks like this:

List<Tuple<string, string>> CustomLineItemParameters { get; set; }

When trying to deserialise the JSON object, I get a list of three tuples, but the tuple values are empty:

[0] -> {(, )}
[1] -> {(, )}
[2] -> {(, )}

How should my model look in order to properly deserialize the json? (I can't change the json structure).

5
  • you post method are you using Json.strngify? Commented Jan 25, 2017 at 16:16
  • Try List<KeyValuePair<string, string>> orDictionary<string,string> Commented Jan 25, 2017 at 16:16
  • @Yashveer i use postman for posting. Commented Jan 25, 2017 at 16:19
  • @Developer same issue with KeyValuePair, already tried it. For Dictionary<string,string> the dictionary is null on deserialisation. Commented Jan 25, 2017 at 16:20
  • Yeah my bad. For Dictionary, the it should be json object not array. And for KeyValuePair, I think the key and value properties are required, notbsure though Commented Jan 25, 2017 at 16:52

1 Answer 1

1
List<Dictionary<string, string>> CustomLineItemParameters { get; set; }
Sign up to request clarification or add additional context in comments.

2 Comments

That worked, thanks! Do you know why Tuple<string, string> or KeyValuePair<string, string> don't work?
Tuples are just regular objects. The default JSON serializer would inflate values in their Item1 and Item2 properties if the incoming object had them. The same applies to KeyValuePair. The Dictionary object is an exception. I think it implements an interface but I can't tell you for sure.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.