Made additions to your program to parse Json data and view/save.
Many users of the forum know the built-in functions of (x)Harbour for json.
Json encoding and decoding is so simple that I prefer to use my own conversion.
Here it is:
- Code: Select all Expand view
#include "fivewin.ch"
function Main()
local odoc := CreateObject( "MSXML2.DOMDocument" )
local ohttp := CreateObject( "MSXML2.XMLHTTP" )
local strret
ohttp:Open( "GET" ,"http://www.w3schools.com/angular/customers.php", .F. )
ohttp:SetRequestHeader( "Accept" , "application/xml")
ohttp:SetRequestHeader( "Content-Type" ,"application/json" )
oDoc:async := .f.
oDoc:LoadXml('<?xml version=""1.0"" encoding=""utf-8""?>')
ohttp:Send(oDoc:xml)
strret := alltrim(ohttp:responseText)
? strret
StrToHashArray( StrRet )
return nil
function StrToHashArray( cStr )
local hHash, aHash
cStr := CharRepl( "[]", RangeRem( 1, 31, cStr ), "{}" )
do while '" :' $ cStr
StrTran( cStr, '" :', '":' )
enddo
cStr := StrTran( cStr, '":', '"=>' )
hHash := &cStr
aHash := HGetValueAt( hHash, 1 )
xbrowser aHash setup ( obrw:autofit(), oBrw:bRClicked := { |r,c,f,o| o:ToDbf( "download.dbf", nil, nil, .t. ) } )
return nil
In case you are using an older version of FWH, you may remove "obrw:autofit()," from the above code.
Result of ? strret: (your program)
This text is converted into an array of Hashes, aHash and displayed in xbrowse:
Right-clicking the browse lets you save the data to "download.dbf"
This is the downloaded data in download.dbf