[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 ?



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
-----------------------------------------------------------------------