Topic
  • 3 replies
  • Latest Post - ‏2011-08-19T20:50:41Z by ClaudeFalbriard
SystemAdmin
SystemAdmin
9224 Posts

Pinned topic How to read data of complex request json objects from java code ?

‏2011-08-18T07:48:34Z |
Hello,

I am doing POST request (with dojo.xhrPost) from my js-page and send following content to the server:

my_key:

My server side is written in java and I want to read the data of my_key.
I am trying with GlobalContext.zget("/request/params/my_key"). I see it returns a complex object (object Object), but I don't know how to read data from this object.

Can anybody help ?

Thank you,
Arkady.
Updated on 2011-08-19T20:50:41Z at 2011-08-19T20:50:41Z by ClaudeFalbriard
  • SystemAdmin
    SystemAdmin
    9224 Posts

    Re: How to read data of complex request json objects from java code ?

    ‏2011-08-18T07:51:34Z  
    Sorry, something was broken during "Post Message" :

    my_key:
  • SystemAdmin
    SystemAdmin
    9224 Posts

    Re: How to read data of complex request json objects from java code ?

    ‏2011-08-18T07:53:37Z  
    Sorry, something was broken during "Post Message" :

    my_key:
    I can't success to past the content of "my_key", but this is complext JSON object which contains list of JSON objects.
  • ClaudeFalbriard
    ClaudeFalbriard
    1 Post

    Re: How to read data of complex request json objects from java code ?

    ‏2011-08-19T20:50:41Z  
    to read a parameter from a form (HTML POST) at the sMash resource code (sample in Groovy), use:

    below a Groovy resource to test it:

    def onCreate() {
    ..
    def keys = zlist('/request/params', true);
    logger.INFO { "keys =" + keys }
    def myKey = zget('/request/params/my_key')
    logger.INFO { "myKey =" + myKey }
    ..

    Observe that params produce a list with the form elements, each one contains a pair of name : value, which can be indexed and you can loop through the form parameter list reading each of the elements. sMash also addresses the element directly and returns an object, I guess its a String object. Sure you try to run exactly the same syntax using a Java resource code:
    String myKey = GlobalContext.zget('/request/params/my_key')  
     
    or 
     
    LinkedList list = GlobalContext.zlist('/request/params', true);
    String myKey = list['my_key'];
    


    Edited by: jeffo_admin on Aug 19, 2011 4:49 PM - added code tags around source
    Updated on 2014-03-25T05:44:37Z at 2014-03-25T05:44:37Z by iron-man