Does anyone have a json reader
- Rick Lipkin
- Posts: 2668
- Joined: Fri Oct 07, 2005 1:50 pm
- Location: Columbia, South Carolina USA
Does anyone have a json reader
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
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
- Enrico Maria Giordano
- Posts: 8728
- Joined: Thu Oct 06, 2005 8:17 pm
- Location: Roma - Italia
- Contact:
Re: Does anyone have a json reader
Try HB_JSONDECODE(), it produces an hash that can then be navigated.
Re: Does anyone have a json reader
Después de convertir la cadena json en hash
Posiblemente esto te pueda ayudar
http://forums.fivetechsupport.com/viewt ... da7cfa42d0
Code: Select all | Expand
aHasRes := hash()
hb_jsondecode(cJson ,@aHasRes)
http://forums.fivetechsupport.com/viewt ... da7cfa42d0
Saludos
LEANDRO AREVALO
Bogotá (Colombia)
https://hymlyma.com
https://hymplus.com/
leandroalfonso111@gmail.com
leandroalfonso111@hotmail.com
[ Embarcadero C++ 7.60 for Win32 ] [ FiveWin 23.07 ] [ xHarbour 1.3.0 Intl. (SimpLex) (Build 20230914) ]
LEANDRO AREVALO
Bogotá (Colombia)
https://hymlyma.com
https://hymplus.com/
leandroalfonso111@gmail.com
leandroalfonso111@hotmail.com
[ Embarcadero C++ 7.60 for Win32 ] [ FiveWin 23.07 ] [ xHarbour 1.3.0 Intl. (SimpLex) (Build 20230914) ]
- Marc Venken
- Posts: 1481
- Joined: Tue Jun 14, 2016 7:51 am
- Location: Belgium
Re: Does anyone have a json reader
Maybe you can see stuff insite the working function ? Stripped the retrive API calls
Code: Select all | Expand
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
Marc Venken
Using: FWH 23.08 with Harbour
Using: FWH 23.08 with Harbour
- Marc Venken
- Posts: 1481
- Joined: Tue Jun 14, 2016 7:51 am
- Location: Belgium
Re: Does anyone have a json reader
These can be interesting :
hb_hGet = to look voor a header like "price" and return the value
cPrice = str(hb_hGet(hDatos, "price"),9,2)
Sometimes the Json has multiple arrays insite
sample Json data : prices":{"basePrice":"44.8900","normalPrice":"44.8900","price":"40.5000","specialPrice":"40.5000","purchasePrice":"0.0000"}
? hDatos[ "prices", "specialPrice" ] // is correct value 40.50
hb_hGet = to look voor a header like "price" and return the value
cPrice = str(hb_hGet(hDatos, "price"),9,2)
Sometimes the Json has multiple arrays insite
sample Json data : prices":{"basePrice":"44.8900","normalPrice":"44.8900","price":"40.5000","specialPrice":"40.5000","purchasePrice":"0.0000"}
? hDatos[ "prices", "specialPrice" ] // is correct value 40.50
Marc Venken
Using: FWH 23.08 with Harbour
Using: FWH 23.08 with Harbour
Re: Does anyone have a json reader
Rick,
This is what I do:
The LOCAL gives me a hash.
cResponse contains the JSON code. Using that function, the Json is transferred to the hash
"sid" is the identifier for the data I want. HB_HGET( ) searches the hash for that identifier and returns it's value.
You can use as many identifiers as you want, and as many HB_HGET's to get their values.
Saving them into a variable allows you to use the value, or you can write it to a DBF.
If you don't know the identifiers, just do an XBROWSE( ) on the hash file. The first column will be the identifier, and the second column the value. When you receive the Json responses, those identifiers will be consistent, so you can grab just the ones you want out of each reply. Of course, make sure you initialize the variables first to empty values so if nothing is returned, you won't have an error.
I hope this helps. In fact, I just did this yesterday when setting up the log system for text messages, and their replies.
This is what I do:
Code: Select all | Expand
LOCAL hInitData := { => }
// Lets decode the response
hb_JsonDecode( cResponse, @hInitData )
cReply := HB_HGET( hInitData, "sid") // Message id
cResponse contains the JSON code. Using that function, the Json is transferred to the hash
"sid" is the identifier for the data I want. HB_HGET( ) searches the hash for that identifier and returns it's value.
You can use as many identifiers as you want, and as many HB_HGET's to get their values.
Saving them into a variable allows you to use the value, or you can write it to a DBF.
If you don't know the identifiers, just do an XBROWSE( ) on the hash file. The first column will be the identifier, and the second column the value. When you receive the Json responses, those identifiers will be consistent, so you can grab just the ones you want out of each reply. Of course, make sure you initialize the variables first to empty values so if nothing is returned, you won't have an error.
I hope this helps. In fact, I just did this yesterday when setting up the log system for text messages, and their replies.
Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
- nageswaragunupudi
- Posts: 10691
- Joined: Sun Nov 19, 2006 5:22 am
- Location: India
- Contact:
Re: Does anyone have a json reader
Browsing a nested Json using HashTree
Now, the function HASHTREE handles nested hashes only, but not nested hashes/arrays. We will improve this for the next version. so that any complext Json can be viewd.
Code: Select all | Expand
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"
Now, the function HASHTREE handles nested hashes only, but not nested hashes/arrays. We will improve this for the next version. so that any complext Json can be viewd.
Regards
G. N. Rao.
Hyderabad, India
G. N. Rao.
Hyderabad, India
- nageswaragunupudi
- Posts: 10691
- Joined: Sun Nov 19, 2006 5:22 am
- Location: India
- Contact:
Re: Does anyone have a json reader
Json Reader:
Code: Select all | Expand
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)" )
Regards
G. N. Rao.
Hyderabad, India
G. N. Rao.
Hyderabad, India