To All
I was given a .Json file and was hoping there is someone in the forum that may have a utility I can use to read the file and then once I can read the file .. I will need to append it to a .dbf.
thanks
Rick Lipkin
aHasRes := hash()
hb_jsondecode(cJson ,@aHasRes)
function WebApi_Inlezen()
local aVelden:={}, lAllexport := .F., lRemove := .f., nOfferte
local aVeldenTarget:={}, cOff, nTel:=0, nTeldone:=0
local nOptie:= 1, lFirst := .t., lFirstpic:=.T.,lFirstATT:=.T., lFotofile:=.T.
local afouten := {}, aNoHex:={}
Local aNoFoto :={}, aprijscontrole:={}
local xValue, ikl, aTest:={}
Local at_kleuren:={}, at_maten:={}
Local Kleur_scheider:={"-","/"}
local hDatos := { => }
local aHashes := {}
local uResponse, cCookies, I, cLink, cUrl,oHttp, cTemp
local lFotoresend:= .F., lReedsdata:=.f.
local awebcol:={}, aMaten:={}, cKleuren:=""
FIELD shopveld, offvraag
FIELD code // shopkleur
// Here was my code to retrieve the JSon Data
// In my case I have a loop running, so the JSon is changed and read every time
uResponse = "Your Jason Data String"
//FW_memoEdit(uResponse)
if at("error",uResponse) > 1 .or. empty(uResponse) // Track errors
aadd(aFouten,"Artikel : "+webshop->SKU+" - "+uResponse)
webshop->(dbskip())
loop
endif
hb_JsonDecode( uResponse, @hDatos ) // -> Put into a Hash
XBROWSER HashTree( hDatos ) TITLE "HASH-TREE" ; // See content with Xbrowse
SETUP ( oBrw:aCols[ 1 ]:AddBitmap( { FWDArrow(), FWRArrow() } ),;
obrw:autofit() )
aHashes = hb_HKeys( hDatos ) // Hash keys into array (needed for my purpose
// Now you can use all items from hDatos (headers see xbrowse) and use them like below
cOnlineCode = hDatos["uprid"] // Uprid = productcode needed to retrieve online
// offer command (change dbf data based on Json data)
nOfferte = hDatos["status"] // Neem de juiste record
webshop->aktief = nOfferte
webshop->online = .t.
// Offerte aanvraag
nOfferte = hDatos["isQuotation"] // Neem de juiste record
do case
case nOfferte = "1" // Json was number, I needed logic
webshop->offvraag = .T.
otherwise
webshop->offvraag = .F.
endcase
// Naam
cNaam = hDatos["name"] // Neem de juiste record
webshop->naamshop = cNaam
// Price
nPrijs = val(hDatos["price"]) // Neem de juiste record
webshop->prijsnew = nPrijs
webshop->(dbskip())
enddo
webshop->(dbunlock())
msginfo("De gegevens werden bijgewerkt : Aantal : "+str(nTel,5))
xbrowser(aFouten)
return
LOCAL hInitData := { => }
// Lets decode the response
hb_JsonDecode( cResponse, @hInitData )
cReply := HB_HGET( hInitData, "sid") // Message id
c := '{"prices":{"basePrice":"44.8900","normalPrice":"44.8900","price":"40.5000","specialPrice":"40.5000","purchasePrice":"0.0000"}}'
hb_jsonDecode( c, @h )
XBROWSER HASHTREE( h, 0 ) TITLE "Hash as Tree"
c := '{"prices":{"basePrice":"44.8900","normalPrice":"44.8900","price":"40.5000","specialPrice":"40.5000","purchasePrice":"0.0000"}}'
hb_jsonDecode( c, @h )
c2 := hb_jsonEncode( h, .t. )
FW_MEMOEDIT( c2, "JSON READER (FWH)" )
Return to FiveWin for Harbour/xHarbour
Users browsing this forum: Google [Bot] and 68 guests