Reputation: 829
I would like to use RestSharp to connect to my ASP.NET WebApi services. The WebApi handles model binding automatically, but it's very specific about how it receives json. For example, consider the following:
Public Class DTO
Property JsonDictionary As Dictionary(Of String, String)
End Class
The ASP.NET WebApi will Model-bind this appropriately if I send this to my POST:
{
"JsonDictionary[0].Key":"key1",
"JsonDictionary[0].Value":"value1"
}
I would like to use RestSharp or JSON.NET to serialize dictionaries in this format and send Content-Type: application/json. Can I use these to accomplish my goal or will I need to write my own serializer? Any help is appreciated.
Upvotes: 1
Views: 1316
Reputation: 829
It became a difficult chore to implement a Json.NET MediaTypeFormatter for ASP.NET WebApi, so I chunked WebApi and decided to go with ServiceStack instead. Much better!
Upvotes: 1
Reputation: 78152
The default JSON serializer is just JSON.NET already, so whatever you pass to AddBody() will be serialized using that if Request.DataFormat = DataFormat.Json.
Upvotes: 0