马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?站点注册
×
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
*/
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 示例json数据:
{
"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"
}演示powerbuilder脚本解析json数据:
//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 = larrayls = 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
| PB9代码,WINXP+PB9下测试通过
sailjson.sru
(10.49 KB, 下载次数: 14)
sailjson.zip
(18.23 KB, 下载次数: 21)
更新官方版本:
sailjson.zip
(21.06 KB, 下载次数: 13)
FROM:http://www.pblsoft.com/sailjson.htm
|