Deserialize JSON string to c# object

后端 未结 6 2114
轻奢々
轻奢々 2020-12-10 01:15

My Application is in Asp.Net MVC3 coded in C#. This is what my requirement is. I want an object which is in the following format.This object should be achieved when I deseri

6条回答
  •  臣服心动
    2020-12-10 02:07

    This may be useful:

    var serializer = new JavaScriptSerializer();
    dynamic jsonObject = serializer.Deserialize(json);
    

    Where "json" is the string that contains the JSON values. Then to retrieve the values from the jsonObject you may use

    myProperty = Convert.MyPropertyType(jsonObject["myProperty"]);
    

    Changing MyPropertyType to the proper type (ToInt32, ToString, ToBoolean, etc).

提交回复
热议问题