|
You mentioned in an earlier thread that you had acquired a license to
Rational
Open Access for RPG. Is there any reason that you're writing a procedure
to do
this instead of using Rational Open Access for RPG?
-Nathan.
----- Original Message ----
From: Aaron Bartell <aaronbartell@xxxxxxxxx>
To: Web Enabling the AS400 / iSeries <web400@xxxxxxxxxxxx>
Sent: Fri, July 16, 2010 9:38:52 AM
Subject: [WEB400] Convert DS/Record to JSON
Hi all,
Been doing a fair amount of RPGUI coding lately (
http://mowyourlawn.com/rpgui.html) and have been writing many misc RPG sub
procs to help with moving data around. One that has bothered me for awhile
now is converting an entire record to a JSON string and back again. For
example, I am writing an app right now that displays "person" information
to
the browser from the PERSONTBL DB2 table and my code looks like this:
chain key PERSONTBL PER;
json_putInt( pJson: 'C@PER#': PER.C@PER#);
json_putInt( pJson: 'C@FAM#': PER.C@FAM#);
json_putInt( pJson: 'C@MPER': PER.C@MPER);
json_putInt( pJson: 'C@SEQ#': PER.C@SEQ#);
json_putString(pJson: 'C@RSHP': PER.C@RSHP);
json_putString(pJson: 'C@SSN': %editc(PER.C@SSN:'X'));
json_putString(pJson: 'C@NAML': PER.C@NAML);
json_putString(pJson: 'C@NAMF': PER.C@NAMF);
json_putString(pJson: 'C@NAMM': PER.C@NAMM);
json_putString(pJson: 'C@NSUF': PER.C@NSUF);
json_putString(pJson: 'C@NAME': PER.C@NAME);
json_putString(pJson: 'C@NAMD': PER.C@NAMD);
json_putString(pJson: 'C@AD1#': PER.C@AD1#);
json_putString(pJson: 'C@AD1N': PER.C@AD1N);
json_putString(pJson: 'C@CITY': PER.C@CITY);
json_putString(pJson: 'C@STA': PER.C@STA);
json_putString(pJson: 'C@ZIP': PER.C@ZIP);
json_putString(pJson: 'C@MADC': PER.C@MADC);
json_putString(pJson: 'C@MAD1': PER.C@MAD1);
json_putString(pJson: 'C@MAD2': PER.C@MAD2);
json_putString(pJson: 'C@MCTY': PER.C@MCTY);
json_putString(pJson: 'C@MAST': PER.C@MAST);
json_putString(pJson: 'C@MZIP': PER.C@MZIP);
json_putString(pJson: 'C@PPH#': PER.C@PPH#);
json_putString(pJson: 'C@PPFL': PER.C@PPFL);
json_putString(pJson: 'C@SPH#': PER.C@SPH#);
json_putString(pJson: 'C@SPFL': PER.C@SPFL);
json_putString(pJson: 'C@TPH#': PER.C@TPH#);
json_putString(pJson: 'C@TPFL': PER.C@TPFL);
json_putString(pJson: 'C@EMAD': PER.C@EMAD);
json_putString(pJson: 'C@FSPH': %char(PER.C@FSPH));
json_putString(pJson: 'C@DOB': %char(PER.C@DOB));
json_putString(pJson: 'C@AGE': %char(PER.C@AGE));
json_putString(pJson: 'C@SEX': PER.C@SEX);
json_putString(pJson: 'C@MSTA': %trim(PER.C@MSTA));
json_putString(pJson: 'C@CTZS': %trim(PER.C@CTZS));
json_putString(pJson: 'C@LANG': PER.C@LANG);
json_putString(pJson: 'C@ITPR': PER.C@ITPR);
json_putString(pJson: 'C@ETHN': PER.C@ETHN);
json_putString(pJson: 'C@STAT': PER.C@STAT);
json_putString(pJson: 'C@BYCK': PER.C@BYCK);
json_putString(pJson: 'C@APPD': %char(PER.C@APPD));
json_putString(pJson: 'C@CUSR': PER.C@CUSR);
json_putString(pJson: 'C@CDAT': %char(PER.C@CDAT));
... and instead of the above I want to do something like this...
chain key PERSONTBL PER;
jsonObj = json_cvtRec(PER: 'PERSONTBL');
Then as long as PERSONTBL is externally defined we could get the layouts of
each field. In theory we should be able to use an incrementing pointer to
"parse" the passed in DS based on the meta data found by calling an API and
passing in the externally define table definition.
I have done this before at a previous employer in a slightly different web
scenario, but unfortunately I don't have access to that code anymore.
Anybody else have a start on a code base that would do something similar to
what I describe above?
Aaron Bartell
http://mowyourlawn.com
http://mowyourlawn.com/blog/
--
This is the Web Enabling the AS400 / iSeries (WEB400) mailing list
To post a message email: WEB400@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/web400
or email: WEB400-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/web400.
--
This is the Web Enabling the AS400 / iSeries (WEB400) mailing list
To post a message email: WEB400@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/web400
or email: WEB400-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/web400.
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.