开发者

converting JSON to an object / dictionary / dynamic

I'm currently using jqGrid to display data. Part of jqGrid's interface will give you search options, posting back the search details in a JSON string, for example:

{
  "groupOp": "AND",
  "rules": [{
    "field": "PersonID",
    "op": "eq",
    "data": "123"
  }, {
    "field": "LastName",
    "op": "eq",
    "data": "Smith"
  }]
}

(meaning i'm searching for personID = 123, and LastName = 'Smith')

so what i'm hoping to do is somehow convert that back in开发者_开发问答to something i can use server-side.

Does anyone have a solution for this that may convert it back into an object of some kind? My current solution would be to convert into xml, parse with linq and create instances of my own 'search' class with a 'rules' collection.


You can use JavaScriptSerializer to serialize/deserialize between json and your Search class.


Json.NET is a very rich JSON parser for .NET (I know, Captain Obvious huh...)

As far as I know, using the built-in JsonDataContractSerializer won't do what you're looking for because it requires a known type that provides the data contract. Without an existing type to deserialize to, it can't just produce a dynamic object.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜