Convert JSON formated String to JsonObject with Jayrock
Assuming json
is the variable containing JSON text, use Jayrock.Json.Conversion.JsonConvert.Import(json)
. What you will get back in return is either a JsonObject
, JsonArray
, JsonNumber
, System.String
, System.Boolean
or a null reference depending on the root JSON value in the source JSON text. If you know it is going to be a JSON object for sure then you can safely cast the return value or use JsonConvert.Import<JsonObject>(json)
.
I would discourage working against JsonObject
directly unless you particularly depend on one of its features. You should just pretend the JSON object you get back is a dictionary; either IDictionary
or IDictionary<string, object>
. With the latest version for .NET Framework 4, you can also work with a JsonObject
as a dynamic object.
I don't know Jayrock, but if you want to accept a JSON object as a parameter of Action in MVC2 than the easiest way to do it is by using JsonValueProviderFactory from Futures assembly.
It's part of System.Web.Mvc in MVC3.