I'm working on this project that needs to serialize JSON objects to post parameters using RestSharp, below is my code:
var request = new RestRequest();
request.Method = Method.POST;
request.RequestFormat = DataFormat.Json;
request.AddBody(jsonObject);
return client.Execute<dynamic>(request);
What I realize is instead of adding each JSON name value pair as a post parameter, request.AddBody adds the whole JSON string as one large post parameter. My question is, is there any way to cause request.AddBody method to add each JSON name-value pair as individual post parameters? I know that request.AddParameter() does the job but that requires manual effort to add each parameter.
Instead of:
[0]:{
application/json="
{
"name":"john doe",
"age": "12",
"gender": "male"}
}
}
Desired Result:
[0]:"name":"john doe"
[1]:"age":"12"
[2]:"gender":"male"
?name=john doe&age=12&gender=malewould be more normative. Can you just confirm if that is the kind of thing you had in mind?