首页 > 其他分享 >Powerbuilder练级攻略003_datawindow绑定接口返回数据

Powerbuilder练级攻略003_datawindow绑定接口返回数据

时间:2023-01-20 10:44:35浏览次数:40  
标签:p022 Powerbuilder 练级 li 003 stu dw curl data

  1. 开发一个接口,确保http://192.168.37.184:10103/demo3的Get请示返回
    {
    "code":0,
    "data":[{"stu_num":1, "stu_name": "张三"},{"stu_num":2, "stu_name": "李四"}],
    "msg":""
    }
    
  2. 新建一个目录,如D:\pb_project\tutorial\p022_dw_http
  3. File-New-Workspace-OK,选中D:\pb_project\tutorial\p022_dw_http,打开,文件名输入p022_dw_http,保存
  4. File-New-Target-Application-OK,Application Name输入p022_app,Finish
  5. 下载https://github.com/bondliu2020/pbidea 把100文件夹下的websuit.pbl和PbIdea.dll复制到p022_dw_http文件夹
  6. 关了所有子窗口,右键p022_app,Library List-Browse,选中刚才复制过来的websuit.pbl,Apply-OK
  7. File-New-DataWindow-Grid-OK-External-next
  8. 加2个字段stu_name,string;stu_num,number,再一直next,最后保存为d_1
  9. 添加一个Windows,选中Windows,Insert-Control-DataWindow,在DataObject上选中刚才建的d_1,保存窗口为w_main
  10. 在w_main的open函数里输入
    string as_url = "http://192.168.37.184:10103/demo3"
    string ls_str
    uo_curl u_curl
    u_curl = Create uo_curl
    u_curl.setUtf8(True)
    u_curl.SetTimeout(10000)
    u_curl.setUrl(as_url,"GET")
    
    boolean a
    a = u_curl.request("")
    uo_json json1
    json1 =  u_curl.response.json
    
    integer code
    uo_json data
    uo_json tmp
    data = Create uo_json
    tmp = Create uo_json
    //json1.get("code", code)
    json1.get("data", data)
    
    integer li_arrcount
    integer li_1
    li_arrcount = data.arrcount( )
    For li_1  = 0 To li_arrcount - 1
    	data.get( "/" + String(li_1) , tmp)
    	integer stuNum
    	string stuName
    	tmp.get("stuNum", stuNum)
    	tmp.get("stuName", stuName)
    	dw_1.insertrow(0)
    	dw_1.setitem(li_1 + 1, "stu_num", stuNum)
    	dw_1.setitem(li_1 + 1, "stu_name",stuName)
    Next
    Destroy u_curl
    Destroy data
    Destroy tmp
    
  11. 在p022_app里输入open(w_main)

标签:p022,Powerbuilder,练级,li,003,stu,dw,curl,data
From: https://www.cnblogs.com/zhouyang209117/p/17062514.html

相关文章