1

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.

2 Answers 2

1

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!

Sign up to request clarification or add additional context in comments.

Comments

0

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.

2 Comments

The beta that is currently on Nuget doesn't use JSON.Net. You can either wait until the VS RC to get that, or go straight for the latest source on codeplex.
So you're saying that if I upgrade to WebApi from CodePlex, then I'll be able to model bind with more flexible JSON options rather than explicitly in the format listed in the original post?

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.