In my web app, the backend is built in ASP.net. The ajax call I'm using is a standard get request.
$.ajax({
url: 'myurl/updatejson',
contentType: "application/json; charset=utf-8",
data: data,
success: function (data) {
// perform actions here
},
error: function (xhr, status, err){
console.error(xhr, status, err);
}
});
The 'data' variable is a simple key-value object that is correctly formatted. In the C# backend code:
public HttpStatusCodeResult UpdateJson(Dictionary<string, object> json){ //perform actions here }
I expected the 'json' variable in C# to be equal to 'key, value', but instead, I received 'key, [value]' for some reason. When I declared the Dictionary as Dictionary<string, string>
instead of Dictionary<string, object>
, everything worked fine and I got the expected result. This suggests that it is converting the string to an object and wrapping it in an array.
Is there a way to use the Dictionary<string, object>
format (as the value could be a string, int, or boolean) without having the value wrapped in an array?