[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: When you ask a webservice in JSON, what do you probably get back ?



   Pete,
   here is a JSON site ...
   http://212.242.251.247:1598
   all RPG
   regards
   henrik

   Pete Helgren <Pete@xxxxxxxxxx>
   Sent by: ftpapi-bounces@xxxxxxxxxxxxxxxxxxxxxx

   03-11-2009 18:13

                             Please respond to
        HTTPAPI and FTPAPI Projects <ftpapi@xxxxxxxxxxxxxxxxxxxxxx>

                                                                       To

   HTTPAPI and FTPAPI Projects <ftpapi@xxxxxxxxxxxxxxxxxxxxxx>

                                                                       cc

                                                                  Subject

   Re: When you ask a webservice in JSON, what do you probably get back ?

   Henry,
   My i side stuff is written in Java.  In fact all of the web
   application
   code I have runs in Java Servlets running under Tomcat.  I do that
   because I have customers that run on i and some who, inexplicably, run
   on Windows servers ;-)
   Basically you need to be familiar with Ajax techniques to start with
   because it is Ajax that will call the server (i) side programs that
   will
   generate the content.  If you are familiar with Ajax, returning JSON
   formatted content is trivial.  If you are not familiar with Ajax, then
   spend some time understanding how it works and write a couple of
   simple
   routines that make the round trip to the server for data. I am sure
   there are several CGIDEV examples that use Ajax so that you could
   write
   some RPG code on the i to generate and deliver the data.
   What JSON brings to the table is that the data is already formatted so
   that Javascript will see it as an object.  If you are using a
   framework
   like jQuery or Dojo or Prototype, working with *objects* becomes
   important and helpful. So JSON complements the so called "Web 2.0"
   techniques by delivering ready to use data objects.
   There is a simple and easy to use and understand JSON example I found
   here: http://www.xul.fr/ajax-javascript-json.html#Example  The data in
   this case is is in a file in the same folder as the HTML (you can run
   this demo without any server side code).  But then you *could* have
   your
   CGIDEV (or whatever i side web application) return the contents using
   an
   ajax call, rather than loading it locally.  Really that would be the
   only difference.  The JSON formatted data is the key, not *where* the
   data comes from.  But, in the example, you can see how easily the data
   can be used once it has been returned as a JSON object.  The menu
   generating code is pretty trivial.
   I *could* write a servlet to return the JSON data that this example
   gets
   from the local folder but that would be overkill and probably wouldn't
   help you if you are looking to write the server side code in RPG.
   I hope this helps a bit.
   Pete
   Kwong, Henry wrote:
   > Hi Pete
   >
   > Can you share with me a sample iseries program to read the JSON
   > response. Our application is very simple, just passing few input
   > parameters, and return with the response code and output parameters.
   > Please help
   >
   >
   > Henry Kwong | Lead System Analyst
   > Mattel Global IT - Managed Services
   > Mattel, Inc. | 333 Continental Blvd. | El Segundo, CA 90245
   > * 310-252-3205 | *  Henry.Kwong@xxxxxxxxxx
   >
   >
   >
   >
   > -----Original Message-----
   > From: ftpapi-bounces@xxxxxxxxxxxxxxxxxxxxxx
   > [mailto:ftpapi-bounces@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of Pete
   Helgren
   > Sent: Wednesday, October 14, 2009 3:58 PM
   > To: HTTPAPI and FTPAPI Projects
   > Subject: Re: When you ask a webservice in JSON, what do you probably
   get
   > back ?
   >
   > Since JSON is *javascript* object notation why would you want to do
   > anything with it on the i?  Just pass it to the browser as a string
   and
   > then let javascript handle it like it is supposed to (maybe "eval"
   it
   > but that is all you'd need).
   >
   > I build JSON data all the time (using Java rather than CGIDEV) and I
   do
   > that specifically because it works so well with javascript,
   otherwise it
   >
   > is rather pointless to create a JSON stream.   If you plan to parse
   it
   > on the i, why not *send* it to the i in something more "readable"?
   >
   > Or is it that some web services only return JSON (haven't run into
   that)
   > and you need to manually parse that out?
   >
   > Pete
   >
   >
   > hr@xxxxxxxxxxxx wrote:
   >
   >>    JSON ;-)
   >>    and there is no way to read JSON on an iSeries,
   >>    so I'm working on a new method that is able to
   >>    convert a recieved JSON object to a XML document
   >>    in the CGIDEV2 Responce Object ....
   >>    Input:
   >>    json = '{'
   >>     + 'data:['
   >>     + '[select:"Y",display:"Y - Yes"]'
   >>     + '  ,[select:"N",display:"N - No"]'
   >>     + ' ] }';
   >>    Output:
   >>    <tree1 type="object">
   >>     <data type="array">
   >>      <tree3 type="array">
   >>       <select>Y</select>
   >>       <display>Y - Yes</display>
   >>      </tree3>
   >>      <tree3 type="array">
   >>       <select>N</select>
   >>       <display>N - No</display>
   >>      </tree3>
   >>     </data>
   >>    </tree1>
   >>    It's a little bit tricky because JSON comes back
   >>    in many formats and not always up to the standards
   >>    descibed.
   >>    But it can be done in rather few statements, and
   >>    here is a first shot that in the end will be packed
   >>    into PXAPICGI in a single method like
   >>    convertJSONtoXML(addr:length);
   >>      buffaddr = bufAddr();
   >>      buffsize = bufSize();
   >>    // do whatever you like
   >>    First shot code:
   >>     /free
   >>      clearSrvPgm();
   >>      setContent('*none');
   >>
   >>      json = '{'
   >>       + 'data:['
   >>       + '[select:"Y",display:"Y - Yes"]'
   >>       + '  ,[select:"N",display:"N - No"]'
   >>       + ' ] }';
   >>
   >>      // packed in method
   >>      nodeDepth = 1;
   >>      nodeLength = 256;
   >>      for i = 1 to NodeLength;
   >>        cPrev = c;
   >>        c = %subst(json:i:1);
   >>        if nodeOpen = *off;
   >>          select;
   >>            when c = *blank;
   >>            when c = '"';
   >>            when c = '{';
   >>              nodeAttr = 'tree'+%char(nodeDepth);
   >>              nodeArray(nodeDepth) = nodeAttr;
   >>              xmlNode(nodeAttr:'type="object"');
   >>              nodeAttr = '';
   >>              nodeDepth += 1;
   >>            when c = '}';
   >>              nodeDepth -= 1;
   >>              xmlEndNode();
   >>            when c = '[';
   >>              nodeAttr = 'tree'+%char(nodeDepth);
   >>              nodeArray(nodeDepth) = nodeAttr;
   >>              xmlNode(nodeAttr:'type="array"');
   >>              nodeAttr = '';
   >>              nodeDepth += 1;
   >>            when c = ']';
   >>              nodeDepth -= 1;
   >>              xmlEndNode();
   >>            when c = ':';
   >>              nodeOpen = *on;
   >>            when c = ',';
   >>            other;
   >>              nodeAttr += c;
   >>          endsl;
   >>
   >>        else;
   >>
   >>          select;
   >>            when nodeOpenC = *on;
   >>              select;
   >>                when c = '"' and cPrev = '\';
   >>                  nodeData += c;
   >>                when c = '\' and cPrev = '\';
   >>                  nodeData += c;
   >>                when c = '"'
   >>                 or c = ' ' and nodeOpenB = *on
   >>                 or c = ',' and nodeOpenB = *on;
   >>                  xmlNode(nodeAttr:'':nodeData);
   >>                  nodeAttr = '';
   >>                  nodeData = '';
   >>                  nodeOpen = *off;
   >>                  nodeOpenC = *off;
   >>                  nodeOpenB = *off;
   >>                other;
   >>                  nodeData += c;
   >>              endsl;
   >>            when c = *blank;
   >>            when c = '"';
   >>              nodeOpenC = *on;
   >>            // number, true, false, null
   >>            when c >= '0' and c <= '9'
   >>             or c = '-'
   >>             or c = '.'
   >>             or c = 't'
   >>             or c = 'f'
   >>             or c = 'n';
   >>              nodeData += c;
   >>              nodeOpenC = *on;
   >>              nodeOpenB = *on;
   >>            when c = '{';
   >>              nodeArray(nodeDepth) = nodeAttr;
   >>              xmlNode(nodeAttr:'type="object"');
   >>              nodeAttr = '';
   >>              nodeDepth += 1;
   >>              nodeOpen = *off;
   >>            when c = '}';
   >>              nodeDepth -= 1;
   >>              xmlEndNode();
   >>            when c = '[';
   >>              nodeArray(nodeDepth) = nodeAttr;
   >>              xmlNode(nodeAttr:'type="array"');
   >>              nodeAttr = '';
   >>              nodeDepth += 1;
   >>              nodeOpen = *off;
   >>            when c = ']';
   >>              nodeDepth -= 1;
   >>              xmlEndNode();
   >>            when c = ':';
   >>            when c = ',';
   >>            other;
   >>          endsl;
   >>        endif;
   >>      endfor;
   >>
   >>      // back on the outside again
   >>      buffaddr = bufAddr();
   >>      buffsize = bufSize();
   >>      dsply result;
   >>      echoToStmf('/json.xml':1252);
   >>      *inlr = *on;
   >>      return;
   >>     /end-free
   >>
   >>
   >>
   ----------------------------------------------------------------------
   >> --
   >>
   >>
   ----------------------------------------------------------------------
   >> - This is the FTPAPI mailing list.  To unsubscribe, please go to:
   >> http://www.scottklement.com/mailman/listinfo/ftpapi
   >>
   ----------------------------------------------------------------------
   >> -
   >>
   >>
   >
   > --------------------------------------------------------
   >
   > This message (including any attachments) is only for the use of the
   person(s) for whom it is intended. It may contain Mattel confidential
   and/or trade secret information. If you are not the intended
   recipient, you should not copy, distribute or use this information for
   any purpose, and you should delete this message and inform the sender
   immediately.
   >
   ----------------------------------------------------------------------
   -
   > This is the FTPAPI mailing list.  To unsubscribe, please go to:
   > http://www.scottklement.com/mailman/listinfo/ftpapi
   >
   ----------------------------------------------------------------------
   -
   >
   >
   ----------------------------------------------------------------------
   -
   This is the FTPAPI mailing list.  To unsubscribe, please go to:
   http://www.scottklement.com/mailman/listinfo/ftpapi
   ----------------------------------------------------------------------
   -
-----------------------------------------------------------------------
This is the FTPAPI mailing list.  To unsubscribe, please go to:
http://www.scottklement.com/mailman/listinfo/ftpapi
-----------------------------------------------------------------------