Example 2 (using JSONPackage, HTTPClient, &
ImportJson)
If the JSON string returned from the RESTFul Web Service is not
a perfect two-level plain JSON string, you may consider using the
JSONPackage object to get the part of JSON string that is the plain
JSON, and then use DataWindow ImportJson or ImportJsonByKey function
to import the JSON data to the DataWindow.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
string ls_value string ls_url string ls_json long ll_return,ll_row httpclient lnv_httpclient jsonpackage lnv_pack1,lnv_pack2 lnv_pack1 = create jsonpackage lnv_pack2 = create jsonpackage lnv_httpclient = create httpclient //Get the JSON string via httpclient ls_url = "https://test.appeon.com/getfood" ll_return = lnv_httpclient.sendrequest("Get",ls_url) if ll_return <> 1 then messagebox("Failed","SendRequest Failed:"+lnv_httpclient.getresponsestatustext( )) return end if lnv_httpclient.getresponsebody( ls_json) /* JSON string returned from the URL: '{ "id": "0001", "type": "donut", "name": "Cake", "ppu": 0.55, "batters": { "batter": [ { "id": "1001", "type": "Regular" }, { "id": "1002", "type": "Chocolate" }, { "id": "1003", "type": "Blueberry" }, { "id": "1004", "type": "Devil~'s Food"}, { "id": "5001", "type": "None" } ] } }'*/ //Load the JSON string via jsonpackage lnv_pack1.loadstring(ls_json) //Get the JSON string under key=batters ls_value = lnv_pack1.getvalue("batters") //Load the new JSON string via jsonpackage lnv_pack2.loadstring( ls_value) //Get the JSON data under key=batter (this json data meets the requirements by RestClient) ls_value = lnv_pack2.getvalue( "batter") //Import JSON data to the DataWindow via importjson dw_1.importjson(ls_value) destroy lnv_pack1 destroy lnv_pack2 destroy lnv_httpclient |
Document get from Powerbuilder help
Thank you for watching.
Subscribe
Login
0 Comments
Oldest