祝愿大家身体健康!

 站点注册  找回密码
 站点注册

QQ登录

只需一步,快速开始

查看: 11266|回复: 7

[参考资料] Pure Powerbuilder script tool to parse json【纯PB脚本工具解释JSON】

[复制链接]

[参考资料] Pure Powerbuilder script tool to parse json【纯PB脚本工具解释JSON】

[复制链接]
ehxz

主题

0

回帖

57万

积分

管理员

积分
570784
贡献
在线时间
小时
2015-2-27 14:16:43 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?站点注册

×
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.
sailjson.jpg

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, 下载次数: 13)
sailjson.zip (18.23 KB, 下载次数: 19)

更新官方版本:
sailjson.zip (21.06 KB, 下载次数: 9)

FROM:http://www.pblsoft.com/sailjson.htm
共享共进共赢Sharing And Win-win Results
SYBASEBBS - 免责申明1、欢迎访问“SYBASEBBS.COM”,本文内容及相关资源来源于网络,版权归版权方所有!本站原创内容版权归本站所有,请勿转载!
2、本文内容仅代表作者观点,不代表本站立场,作者自负,本站资源仅供学习研究,请勿非法使用,否则后果自负!请下载后24小时内删除!
3、本文内容,包括但不限于源码、文字、图片等,仅供参考。本站不对其安全性,正确性等作出保证。但本站会尽量审核会员发表的内容。
4、如本帖侵犯到任何版权问题,请立即告知本站 ,本站将及时删除并致以最深的歉意!客服邮箱:admin@sybasebbs.com
j528

主题

0

回帖

3254

积分

论坛元老

积分
3254
贡献
在线时间
小时
2015-3-2 19:34:23 | 显示全部楼层
本帖最后由 j528 于 2015-6-5 00:12 编辑

{"emp":[{"id":111,"name":"\u5f20\u4e09"},{"id":123,"name":"\u674e\u56db"},{"id":124,"name":"\u738b\u4e94"},{"id":125,"name":"\u8d75\u516d"},{"id":126,"name":"zbao"}]
}

如果json数据是中文,如"name":"\u5f20\u4e09",怎样获取中文字符?


QQ截图20150605001158.png
共享共进共赢Sharing And Win-win Results
fuxiaoyang13

主题

0

回帖

3136

积分

论坛元老

积分
3136
贡献
在线时间
小时
2015-3-4 15:01:17 | 显示全部楼层
学习学习!!!!
共享共进共赢Sharing And Win-win Results
j528

主题

0

回帖

3254

积分

论坛元老

积分
3254
贡献
在线时间
小时
2015-6-24 15:12:12 | 显示全部楼层
//====================================================================
oleobject json
oleobject wsh
wsh = CREATE oleobject
int li_ret
li_ret = wsh.ConnectToNewObject( "MSScriptControl.ScriptControl" )
if li_ret < 0 then
//messagebox
end if

string str
str='{"errcode": 0,"errmsg": "","retcode": 0,"recordlist" : [{ "openid" : "oDF3iY9WMaswOPWjCIp_f3Bnpljk","opercode" : 2002, "text" : " 您好,客服test1为您服务。","time" : 1400563710,"worker" : "test1"},{"openid" : "oDF3iY9WMaswOPWjCIp_f3Bnpljk","opercode" : 2003,"text" : "\u5f20\u4e09", "time" : 1400563731,"worker" : "test1"}]}'
wsh.language = "jscript"
wsh.addcode( " Array.prototype.get = function(idx){ return this[idx]; } ")
wsh.addcode( " Object.prototype.getattr = function(item){ return this[item]; } ")
wsh.addcode( " Array.prototype.item = function(idx,item){ return this[idx][item]; } ")
json = wsh.Eval( '(' + str + ')' )


int tmp,li1
// 例如:注意要(tmp - 1),因为是从0 开始的
tmp=json.recordlist.length      //得出recordlist节点包含的数据行数
for li1=0 to tmp - 1
        messagebox("",string(json.recordlist.item(li1,"text")))  
next
//  即便text里面的字符为unicode的也能被转换为中文
destroy wsh
destroy json
共享共进共赢Sharing And Win-win Results
j528

主题

0

回帖

3254

积分

论坛元老

积分
3254
贡献
在线时间
小时
2015-6-24 15:12:57 | 显示全部楼层
这样就可以用了,可以把上面的代码直接贴到pb里面运行就知道怎样使用了
共享共进共赢Sharing And Win-win Results
tomok

主题

0

回帖

1万

积分

注册会员

积分
18510
贡献
在线时间
小时
2015-8-23 16:32:50 | 显示全部楼层
谢谢 及时 提供
共享共进共赢Sharing And Win-win Results
swimchen

主题

0

回帖

4295

积分

论坛元老

积分
4295
贡献
在线时间
小时
2015-9-3 00:05:21 | 显示全部楼层
不错,这些都是好文章,还可以用INET连接某个网页来处理哦,现在网上有很多这种网页转换XML啦,不过前提得系统能够上网
共享共进共赢Sharing And Win-win Results
qweasd2002

主题

0

回帖

7957

积分

论坛元老

积分
7957
贡献
在线时间
小时
2015-12-17 14:19:43 | 显示全部楼层
这样就可以用了,可以把上面的代码直接贴到pb里面运行就知道怎样使用了
共享共进共赢Sharing And Win-win Results
您需要登录后才可以回帖 登录 | 站点注册

本版积分规则

免责声明:
本站所发布的一切破解补丁、注册机和注册信息及软件的解密分析文章仅限用于学习和研究目的;不得将上述内容用于商业或者非法用途,否则,一切后果请用户自负。本站信息来自网络,版权争议与本站无关。您必须在下载后的24个小时之内,从您的电脑中彻底删除上述内容。如果您喜欢该程序,请支持正版软件,购买注册,得到更好的正版服务。如有侵权请邮件与我们联系处理。

Mail To:Admin@SybaseBbs.com

QQ|Archiver|PowerBuilder(PB)BBS社区 ( 鲁ICP备2021027222号-1 )

GMT+8, 2024-4-29 00:48 , Processed in 0.058792 second(s), 9 queries , MemCached On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表