how to Deserialize getcontent()

4 posts, 0 answers
  1. feras
    feras avatar
    24 posts
    Member since:
    Sep 2008

    Posted 31 Mar 2010 Link to this post

    hi,
    after having some experiments with the panel i think it is really great and correct me if i am wrong but i think i can achieve the same AJAX functionality with jquery templating on the client side with the panel by doing the following technique

    i create a web-service and request it by the panel and what i get is pure JASON, then i deserialize the Jason and use jquery to bind the value using $each function.

    now i got tow questions, how i can deserialize the value comming from server like for example
    {"d":{"__type":"user","name":"james","family":" smith"}}

    i use the following code but nothing happens
     functionResponseEnding(sender, args) {
     

               
                $('#RadTextBox1_text').val(get_content().name);
               
           

            }

    second question is is there a way to loop through template other than using $each function ?

    thanks in advanced.

  2. Lini
    Admin
    Lini avatar
    2144 posts

    Posted 02 Apr 2010 Link to this post

    Hello,

    To deserialize JSON content in the browser, you can use the ASP.NET AJAX client API - http://www.asp.net/AJAX/documentation/live/ClientReference/Sys.Serialization/JavascriptSerializerClass/JavascriptSerializerDeserializeMethod.aspx

    var value = '{"d":{"__type":"user","name":"james","family":" smith"}}';
    var obj = Sys.Serialization.JavaScriptSerializer.deserialize(value);
    //obj.d.name is "james"

    I am not sure which jQuery client templating solution you are using, but $.each() is a good solution for iterating through the elements in the response. See the following blog post for a sample implementation - http://www.west-wind.com/weblog/posts/509108.aspx


    Sincerely yours,
    Lini
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. feras
    feras avatar
    24 posts
    Member since:
    Sep 2008

    Posted 02 Apr 2010 Link to this post

    hi,
    thanks for the reply, but unfortunately it does not work, even with your sample

    here is my code
       function Ending(sender, args) {
             //   var value = '{"d":{"__type":"user","name":"james","family":" smith"}}';
                var value = args.get_content() ;
                var obj = Sys.Serialization.JavaScriptSerializer.deserialize(value);

                alert(obj.d.name);
                $('#RadTextBox1_text').val(obj.d.name);
                $('#test').html(obj.d.name);
              //  args.set_cancel(result);

            }
          
    as you see neither, the alert is showing up or textbox, div is getting any value at my end, plus i get this [object Object] inside RadXMLHTTPPANEL, which  i don't want it to be there,  any clues ?
    thanks in  advanced.

  5. Lini
    Admin
    Lini avatar
    2144 posts

    Posted 02 Apr 2010 Link to this post

    Hello,

    I tried your script and it worked as expected for me. Perhaps the problem is with the value you get from the XmlHttpPanel:

    var value = args.get_content();

    I tried with the hardcoded value and it worked OK - alert showed james, RadTextBox1 value was set to james, content of div element with ID test was set to james.

    var value = '{"d":{"__type":"user","name":"james","family":" smith"}}';


    Kind regards,
    Lini
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Back to Top