How to give a converted object from an json ?

  1. #1

    How to give a converted object from an json ?

    Hi all,

    How i can give a converted object from an json ?

    //run at in client
    Ext.net.DirectMethod.request({
    url          : 'webservice.asmx/save',
    cleanRequest : true,
    json         : true
    , params     : { 
       data      : window.storeIdGenereted.getAt(0).json } } );
    
    //run at server webservice
            [WebMethod(EnableSession=true)]
            public void Salvar(object data)
            {
                   Model.MyType obj = (Model.MyType)data;
            }
    Thx in advanced.
  2. #2
    Hi,

    Please try:
    public void Salvar(string data)
    {
        Model.MyType obj = JSON.Deserialize<Model.MyType>(data);
    }
  3. #3
    Thx again Daniil.

    This example dont works =/

    Throws the Exception:

    {"Message":"No parameterless constructor defined for type of \u0027System.String\u0027.","StackTrace":" at System.Web.Script.Serialization.ObjectConverter.ConvertDictionaryToObject(IDictionary`2 dictionary, Type type, JavaScriptSerializer serializer, Boolean throwOnError, Object& convertedObject)\r\n at System.Web.Script.Serialization.ObjectConverter.ConvertObjectToTypeInternal(Object o, Type type, JavaScriptSerializer serializer, Boolean throwOnError, Object& convertedObject)\r\n at System.Web.Script.Serialization.ObjectConverter.ConvertObjectToTypeMain(Object o, Type type, JavaScriptSerializer serializer, Boolean throwOnError, Object& convertedObject)\r\n at System.Web.Script.Services.WebServiceMethodData.StrongTypeParameters(IDictionary`2 rawParams)\r\n at System.Web.Script.Services.RestHandler.InvokeMethod(HttpContext context, WebServiceMethodData methodData, IDictionary`2 rawParams)\r\n at System.Web.Script.Services.RestHandler.ExecuteWebServiceCall(HttpContext context, WebServiceMethodData methodData)","ExceptionType":"System.MissingMethodException"}
  4. #4
    I solved the problem. Thx Daniil.
    The problem is:

    The tag
    <add name="JSONAsmx" type="JsonHttpModule, App_Code"/>
    has missed in web.config. Sry, My mistache.

    Thx again Daniil. Can close this.
  5. #5
    Thanks for the update.

Similar Threads

  1. [CLOSED] JSON deserialize model fields to one nested object
    By boris in forum 2.x Legacy Premium Help
    Replies: 6
    Last Post: Jul 12, 2012, 10:51 AM
  2. [CLOSED] JSON object property: convert to Date value
    By supera in forum 2.x Legacy Premium Help
    Replies: 4
    Last Post: Jun 14, 2012, 2:50 PM
  3. JSON Object to Store
    By Tbaseflug in forum 1.x Help
    Replies: 0
    Last Post: Oct 11, 2011, 8:44 PM
  4. Replies: 2
    Last Post: May 29, 2011, 3:42 AM
  5. Replies: 4
    Last Post: Feb 02, 2010, 1:00 PM

Posting Permissions