I have below code written to test for reading the dictionary key and values from Postman.
C# web api method:
[OperationContract]
[WebInvoke(Method = "POST", UriTemplate = "Service/testdictionary",
BodyStyle = WebMessageBodyStyle.WrappedRequest)]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public void testdictionary(Dictionary<string,object> data)
{
if(data != null)
{
string str1 = data["a1"].ToString();
string str2 = data["a2"].ToString();
string str3 = data["a3"].ToString();
}
}
Postman input Body:(raw and JSON(application/json))
{
"data": {
"a1": "b1",
"a2": "b2",
"a3": "b3"
}
}
How am I calling the method from Postman:
What is the issue: Whenever I am trying to assign dictionary object data from the postman, in C# code it is getting assigned as an empty dictionary.
What is required: I want to read a dictionary element from postman to my API code.