sailjson |
Powerbuilder json parser |
|
|
|
|
|
sailjson |
Pure Powerbuilder script tool to parse json |
|
sailjson is a none visual user object for powerbuilder. This
demo writted in Powerbuilder 9.
You can free download sailjson and
use it, but please keep the site address mark in script.
/*
Sailjson:from www.pblsoft.com
Please reserve this information
Version:2.2
Release date:2016-6-27
Fixed bug of read string which include "\".
Version:2.1
Release date:2016-1-9
Fixed bug to parse pure array like "[1,2,3,4]" json string.
Version:2.0
Release date:2016-1-1
Add function to parse array of string or number,not only the object
*/
sailjson provide follow
functions to parse json data.
//the four function to parse
json data and get values
public function string parse
(string as_json)
public function integer getarray (string itemname, ref any va[])
public function boolean isarray (any value)
public function any getattribute (string itemname)
//this function to display json
format in treeview
public subroutine buildtree (treeview atree, long handle,
integer aobjectpcxidx, integer aarraypcxidx, integer aitempcxidx)
//the four function modify json
data structure and get json data
public subroutine setattribute (string as_name, any aa_value)
public function any addarrayitem (string arrayname)
public function any addobject (string objname)
public function string getformatjson (string ident) //if ident='',
will get packed json data
Please down load the demo to see
details using.
|
|
Example Scripts
Example json data:
{
"version": "1001",
"header": {
"count": 3,
"comment": "items
count"
},
"data": [
{
"colid": 1,
"colname": "aaaaaa",
"coladdr": ""
},
{
"colid": 2,
"colname": "bbbbbbbb",
"coladdr": null
},
{
"colid": 3,
"colname": "cccccc"
}
],
"creattime":
"20150213.084829"
}
demo powerbuilder script to parse the json data:
//this demo script parse the json data
sailjson json, ljson
string ls_json, ls
ls_json = '{"version":"1001","header":{"count":3,"comment":"itemscount"},"data":[{"colid":1,"colname":"aaaaaa","coladdr":""},{"colid":2,"colname":"bbbbbbbb","coladdr":null},{"colid":3,"colname":"cccccc"}],"creattime":"20150213.084829"}'
json = create sailjson
json.parse( ls_json )
//get
version
ls = json.getattribute( 'version')
//get header, header is an
object in json data
ljson = json.getattribute('header')
ls = string(ljson.getattribute('count'))
ls = ljson.getattribute('comment')
integer i,li_count
any larray[]
//get data, data is array of
objects
li_count = json.getarray( 'data',
larray)
for i = 1 to li_count
ljson = larray[i]
ls = string(ljson.getattribute( 'colid'))
ls = ljson.getattribute( 'colname')
if isnull(ljson.getattribute( 'coladdr')
) then
ls = 'null'
else
ls = ljson.getattribute( 'coladdr')
end if
next
ls = json.getattribute( 'createtime')
//to
display json format in treeview
integer handle
handle =
tv_1.insertitemfirst(0, 'root',
2)
json.buildtree( tv_1, handle,
2,3,1)
tv_1.expanditem( handle)
destroy json
|
|