1. #1
    Ext User
    Join Date
    Sep 2008
    Posts
    25
    Vote Rating
    0
    Litre is on a distinguished road

      0  

    Default How do you handle Java JSON return data?

    How do you handle Java JSON return data?


    ExtJS JSON and Java Struts:

    I like to use struts action calls, unfortunately the Java JSON toString() method returns JSON suited to Java only, that is with backslash escaped quotations and enclosing double quotes.

    Everytime I deal with a Java outputted JSON I have to
    replace(/\\/g, "")
    substring(1, responseText.length - 1)

    When I work with TreeLoader I need to override its processResponse, everytime!



    Did I miss something fundamental? Am I doing this wrong? I'm sure others using Java have run into the same thing. Is it a bug? Maybe ExtJS should parse for backslashes and enclosing double quotes?
    Last edited by Litre; 24 Jan 2010 at 9:46 AM. Reason: Title

  2. #2
    Sencha - Ext JS Dev Team Animal's Avatar
    Join Date
    Mar 2007
    Location
    Notts/Redwood City
    Posts
    30,501
    Vote Rating
    47
    Animal has a spectacular aura about Animal has a spectacular aura about

      0  

    Default


    Y'wha?

    http://json.org/

    It just works.

  3. #3
    Ext User
    Join Date
    Sep 2008
    Posts
    25
    Vote Rating
    0
    Litre is on a distinguished road

      0  

    Default


    The dataUrl for my treeLoader calls action OrderTreeMain.action:
    <struts>
    <package name="almatree_order" extends="struts-default, json-default">
    <action name="OrderTreeMain" class="com.almatree.actions.order.OrderTreeAction" method="treeMain">
    <result type="json">
    <param name="root">treeMainReturn</param>
    </result>
    </action>
    </package>
    </struts>

    I then set and return the variable treeMainReturn:
    setTreeMainReturn(rootJSONArray.toString());

    rootJSONArray is a class in library straight from http://www.json.org/java/

    What gets passed back by struts is:
    "[{\"id\":\"order|2\",\"text\":\"Clarence Liu - ClicPen.ca: 46000053\",\"dragText\":\"2|customerId\",\"allowDrop\":false,\"iconCls\":\"leafIcon\"},{\"id\":\"order|242\",\"text\":\"Clarence Liu - AddMyCard.com: 30000012\",\"dragText\":\"242|customerId\",\"allowDrop\":false,\"iconCls\":\"leafIcon\"}]"

    I tried passing the JSONArray directly, by declaring that as the exposed variable, but nothing seems to happen. I assume the problem is I shouldn't be calling toString on the JSONArray but I haven't gotten that to work yet. Does anyone use ExtJS with JSON and struts and know what I'm missing?
    Last edited by Litre; 24 Jan 2010 at 2:39 PM. Reason: grammar

  4. #4
    Ext User jjulian's Avatar
    Join Date
    Jul 2009
    Posts
    36
    Vote Rating
    0
    jjulian is on a distinguished road

      0  

    Default


    Your JSON string is getting "escaped" somewhere between toString() and serving by your web container. I'd wager it's somewhere in Struts. Find where strings are getting escaped, and turn it off for that action.

  5. #5
    Ext User
    Join Date
    Sep 2008
    Posts
    25
    Vote Rating
    0
    Litre is on a distinguished road

      0  

    Default


    Ya looks like it, print to stdout shows no backslashes, documentation shows an escape="false" xml tag in property element but not a result or param, sigh... Guess I'll go bug the struts json-plugin forum.

  6. #6
    Ext User
    Join Date
    Oct 2008
    Posts
    2
    Vote Rating
    0
    jahanzaibi is on a distinguished road

      0  

    Default


    http://cwiki.apache.org/WW/json-plugin.html
    The JSON plugin provides a "json" result type that serializes actions into JSON. The serialization process is recursive, meaning that the whole object graph, starting on the action class (base class not included) will be serialized (root object can be customized using the "root" attribute). If the interceptor is used, the action will be populated from the JSON content in the request, these are the rules of the interceptor:

Turkiyenin en sevilen filmlerinin yer aldigi xnxx internet sitemiz olan ve porn sex tarzi bir site olan mobil porno izle sitemiz gercekten dillere destan bir durumda herkesin sevdigi bir site olarak tarihe gececege benziyor. Sitenin en belirgin ozelliklerinden birisi de Turkiyede gercekten kaliteli ve muntazam, duzenli porno izle siteleri olmamasidir. Bu yuzden iste. Ayrica en net goruntu kalitesine sahip adresinde yayinlanmaktadir. Mesela diğer sitelerimizden bahsedecek olursak, en iyi hd porno video arşivine sahip bir siteyiz. "The Best anal porn videos and slut anus, big asses movies set..." hd porno faketaxi