JsonView( cJson )
XBROWSER HashTree( hb_jsonDecode( cJson ) )
Kleur
Maten
Kleur_D
Kleur_L
#include "FiveWin.ch"
function Main()
local hJson
hb_jsonDecode( memoRead( "jason.txt" ), @hJson )
XBROWSER HashToArray( hJson )
return nil
function HashToArray( hData )
local aData := {}, xItem
for each xItem in hData
if ValType( xItem ) $ "HA"
AAdd( aData, HashToArray( xItem ) )
else
AAdd( aData, xItem )
endif
next
return aData
#include "fivewin.ch"
STATIC oWnd, oBmp, oSay, oBrush
FUNCTION Main()
Json_dbfs() // make a dbf for each group
Json_onedbf() // make one dbf and name a field as group
msginfo("Done")
RETURN NIL
function Json_dbfs()
local hJson, h, I, aCols
Local uResponse, aTest, aData
// This is how I read a Jason
//cLink = "https://domain.be/api/v2/options?token=cToken"
//MsgRun( cLink, "READING FORUM PAGE", { || uResponse := WebPageContents( cLink, .t. ) } )
//St := memowrit("c:\fwharb\samples\Jason.txt",uResponse)
hb_jsonDecode( memoRead( "Jason.txt" ), @h )
aTest:= HashToArray( h )
xbrowser(aTest)title "aTest"
// In this browse you see how many fields are needed. Or you make a function to autocreate the dbf
// of you hard code it like below.
for i = 1 to len(aTest)
cDbf = lower(left(aTest[i][3],8))+"_"+alltrim(str(i))
aData:= HashToArray( aTest[i][7] )
//xbrowser(aData) title aTest[i][3] // If you want to see each group before making
makedbf(cDbf)
FW_ArrayToDBF( aData )
//DBEVAL : could not get this working ....
//DBEVAL( { || If( empty(DTA->TYPE) ,DTA->TYPE = aTest[i][3]),NIL) } )
//DBEVAL( { || If( empty(DTA->TYPE),DTA->TYPE = "TEST",,NIL) } )
//DBEVAL( { || DTA->TYPE = "TEST" } )
DTA->(dbgotop())
do while !dta->(eof())
if empty(DTA->type)
DTA->type = aTest[i][3]
endif
dta->(dbskip())
enddo
XBROWSER "DTA" title cDbf
CLOSE DTA
next
return nil
function HashToArray( hData )
local aData := {}, xItem
for each xItem in hData
if ValType( xItem ) $ "HA"
AAdd( aData, HashToArray( xItem ) )
else
AAdd( aData, xItem )
endif
next
return aData
function MakeDbf(cDbf)
aCols := { { "ID", "N", 6, 0 }, ;
{ "TAAL", "N", 1, 0 }, ;
{ "NAAM", "C", 20, 0 }, ;
{ "Sort", "N", 5, 0 }, ;
{ "HEX", "C", 8, 0 }, ;
{ "TYPE", "C", 25, 0 } }
cDBF := cDbf + ".DBF"
cDBF := TrueName( cDBF )
DBCREATE( cDBF, aCols, "DBFCDX", .T., "DTA" )
return NIL
function Json_onedbf()
local hJson, h
Local uResponse, aTest, aData
//cLink = "https://domain.be/api/v2/options?token=cToken"
//MsgRun( cLink, "READING FORUM PAGE", { || uResponse := WebPageContents( cLink, .t. ) } )
//St := memowrit("c:\fwharb\samples\Jason.txt",uResponse)
hb_jsonDecode( memoRead( "jason.txt" ), @h )
makedbf("jasondata")
aTest:= HashToArray( h )
xbrowser(aTest)title "aTest"
for i = 1 to len(aTest)
aData:= HashToArray( aTest[i][7] )
xbrowser(aData) title aTest[i][3]
FW_ArrayToDBF( aData )
//DBEVAL( { || If( empty(DTA->TYPE) ,DTA->TYPE = aTest[i][3]),NIL) } )
//DBEVAL( { || If( empty(DTA->TYPE),DTA->TYPE = "TEST",,NIL) } )
//DBEVAL( { || DTA->TYPE = "TEST" } )
DTA->(dbgotop())
do while !dta->(eof())
if empty(DTA->type)
DTA->type = aTest[i][3]
endif
dta->(dbskip())
enddo
next
XBROWSER "DTA"
CLOSE DTA
return nil
Return to FiveWin for Harbour/xHarbour
Users browsing this forum: Google [Bot] and 109 guests