I also want the Json into a Dbf and i'm very close to succeed i think. The sample will show severall stages of data, but I think that there is usefull code insite for you issues.
It's a working sample, but a error at the end that i need to look into.. Just not able to write the dbf.
The // comments is for my thinking, so not directed to you, but maybe they can help
Code: Select all | Expand
#include "FiveWin.ch"Function Main
() local oWnd, oActiveX1, oActiveX2, cTemp
DEFINE WINDOW oWnd
TITLE "FiveWin multiple ActiveX support" @
9,
5 BUTTON "&Hash" OF oWnd
SIZE 40,
20 ACTION TestHash
() ACTIVATE WINDOW oWnd
return nil#include "Fivewin.ch"//----------------------------------------------------------------------------//Function TestHash
() local hDatos :=
{ =>
} local aTest :=
{} local aResult :=
{} local aFields :=
{} local m
local uResponse, cCookies, I
uResponse :=
'{"uprid":"2550","productId":"2550","stockId":"-1","referenceId":"0","isBundle":"0","bundledProducts":"[]","status":"1","quantity":"0","maximumQuantity":"null","ean":"98745123456","sku":"skuData","model":"APITEST","hsCode":"","name":"Noyca","price":"0.0000","taxClassId":"3","taxRate":"21.0000","isPhysical":"1","isDigital":"0","isQuotation":"0","url":"onderhoud\/api-test","urlAbs":"https:\/\/http://www.maveco-webshop.be\/onderhoud\/api-test","attributesString":"","backOrder":0,"onHome":0,"layover":0,"configurationAllowCheckout":0,"configurationStockCheck":0,"attributes":[],"description":"Memo<b>Data<\/b>","addonInstagramEnabled":"0","addonInstagram":"0","addonOcsEnabled":"0","dateAdded":"2021-10-30 18:40:57","lastModified":"2021-10-30 19:17:39","descriptions":{"description":"Memo<b>Data<\/b>","extra":"","intro":""},"images":["5101000.jpg","","","","","","","","","","",""],"image_alt":["","","","","","","","","","","",""],"discounts":{"name":"0","groupDiscount":"0.00","groupDiscountCategory":"0.00","groupDiscountProduct":"0.00"},"category":{"id":"888982","name":"Onderhoud","categoryIds":"888982","cPath":"888982"},"quantities":{"quantity":"0","physicalQuantity":"0","minimumQuantity":"0","maximumQuantity":null,"externalQuantity":"0","quantityStep":"1","trackQuantity":"1"},"prices":{"basePrice":"0.0000","normalPrice":"0.0000","price":"0.0000","specialPrice":"0.0000","purchasePrice":"0.0000"},"manufacturer":{"id":0,"name":"","image":""},"dimensions":{"type":"0","width":0,"height":0,"area":0,"weight":0},"reviews":{"count":0,"avg":0},"resources":[],"addons":{"multicatalog":{"enabled":false},"layover":{"enabled":true}}}' hb_JsonDecode
( uResponse, @hDatos
) // -> Hash XBrowse( hb_hKeys
( hDatos
) ) // -> Array XBrowse( hb_hValues
( hDatos
) ) // -> Array XBrowse( hDatos
) // simple key cCookies :=
If( hb_HHasKey
( hDatos,
"name" ), hb_hGet
( hDatos,
"name" ),
"Not Found" ) msginfo(cCookies
) // Found // complex key a array insite a field // "prices":{"basePrice":"0.0000","normalPrice":"0.0000","price":"0.0000","specialPrice":"0.0000","purchasePrice":"0.0000"} // Extract 1 complex key if the keyname is known if hb_HHasKey
( hDatos,
"prices" ) msginfo("Found") XBrowse( hb_hKeys
( hDatos
["prices"] ) ) // is showing the items insite the sub array XBrowse( hb_hValues
(hDatos
["prices"] ) ) // -> Array XBrowse( hDatos
["prices"] ) // Items and Values subarray // At this point, I could stuff the data insite a dbf. I have fields and values else msginfo("Not Found") endif // extract all keys, not knowing if there are subarray (keys) aTest = hb_hKeys
( hDatos
) // -> Array xbrowse(aTest
) for i =
1 to len
(aTest
) cZoek = aTest
[i
] msginfo(cZoek
) if hb_HHasKey
( hDatos, cZoek
) aResult = hDatos
[cZoek
] // -> Array XBrowse( aResult
) // is showing the items, also the subitems // Here I want to build a array (aFields) with all the keys that are seen, with there values. // not working for m =
1 to len
(aResult
) aadd
(aFields,aResult
) next m
//XBrowse( aResult ) // is showing the items insite the sub array endif //XBrowse( aFields ) // is showing the items insite the sub array // Build the dbf with the array. // Maybe better to build a single Hash with all fields. Than a hashtodbf save can be done. nextReturn nil