[CLOSED] Proper Ext.encode() usage

  1. #1

    [CLOSED] Proper Ext.encode() usage

    Hi,

    This question has probably been asked several times before but I still couldn't string all the info together. I'm trying to HTML-encode a string on the client and then decode it on the server. If I use Ext.encode(), what's the appropriate method to decode it on the server? What's the reverse sequence like if a string needs to be encoded on the server first and then decoded on the client? Several encoding methods are available provided by both ASP.Net and Ext.Net and obviously they don't mix well. There's that HttpUtility class and a rich Ext.Net.Utilities namespace to choose from. For now, I've resorted to using the generic window.escape() method on the client with subsequent Ext.Net.Utilities.EscapeUtils.Unescape() method call on the server.
    Could you please provide an example or tutorial link where one encoding method should be chosen over another?
    Last edited by Daniil; Apr 19, 2013 at 3:23 PM. Reason: [CLOSED]
  2. #2
    Hi Vadym,

    Ext.encode() is a shorthand of Ext.util.JSON.encode().
    http://docs.sencha.com/extjs/3.4.0/#...-method-encode

    So, it is for encoding JSON objects.

    On server you should deserialize it. You can use JSON.Deserialize().

    Another thing is encoding HTML.
    http://docs.sencha.com/extjs/3.4.0/#...hod-htmlEncode

    To decode it on server you can use System.Web.HttpUtility.HtmlDecode().

    Hope this helps.
  3. #3
    Thanks for your response Daniil! Does Ext.encode() take adequate care of special characters and sequences so I don't have to worry escaping them? Also, I realize JSON.stringify() should not be used in conjunction with Ext.encode(), correct?
  4. #4
    Quote Originally Posted by vadym.f View Post
    Does Ext.encode() take adequate care of special characters and sequences so I don't have to worry escaping them?
    I don't think so. It is the different tasks to encode a JSON object and some HTML string.


    Quote Originally Posted by vadym.f View Post
    Also, I realize JSON.stringify() should not be used in conjunction with Ext.encode(), correct?
    I think it should not.

    Ext.encode() knows about JSON.stringify() and this method is used if Ext.USE_NATIVE_JSON is true. It is false by default.
    http://docs.sencha.com/extjs/3.4.0/#...SE_NATIVE_JSON
  5. #5
    I see. Do you think one should escape the encoded JSON object before transferring the data to the server?

    Client side:
    var jsonObject=getJsonObject();
    var jsonString=escape(Ext.encode(jsonObject));
    X.HandleJsonObject(jsonString,
    {
        eventMask: { showMask: true },
        success: function(result) { /* do something here */ }
    });
    Server side:
    [DirectMethod]
    public static bool HandleJsonObject(string jsonString)
    {
        var myJson = JSON.Deserialize<MyJsonObject>(Ext.Net.Utilities.EscapeUtils.Unescape(jsonString));
        return myJson is MyJsonObject;
    }
  6. #6
    Not sure, but I have never used the escape method yet before sending something to a server.

    Though it doesn't mean there is no chance that it might be required.
  7. #7
    Thanks Daniil,

    I've got a better grip on the subject, please close this down.

Similar Threads

  1. Replies: 7
    Last Post: Sep 26, 2012, 7:46 PM
  2. [CLOSED] Url encode
    By rnfigueira in forum 1.x Legacy Premium Help
    Replies: 3
    Last Post: Apr 10, 2012, 7:18 PM
  3. JSON encode records of a store
    By Wtower in forum 1.x Help
    Replies: 3
    Last Post: Aug 11, 2009, 1:59 PM
  4. GridPanel Ext.encode all rows
    By OneWingedAngel in forum 1.x Help
    Replies: 4
    Last Post: Feb 08, 2009, 4:31 PM
  5. [CLOSED] How to URL Encode a string
    By iansriley in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Jan 13, 2009, 3:11 PM

Tags for this Thread

Posting Permissions