Welcome! Log In Create A New Profile

Advanced

[WD23] JSONVersVariant (Exemple) ???

Posted by infos 
[WD23] JSONVersVariant (Exemple) ???
October 01, 2021 01:06PM
Hello everyone

I am trying to load the exchange rate list in JSON format [https://www.cbbh.ba/CurrencyExchange/GetJson?date=10%2F01%2F2021%2000%3A00%3A00] using the WD tool JSONVersVariant (Exemple) as given in the example .
All my attempts did not bear fruit.

Have any of you done anything similar in your app.

My code:

MaReq is restRequest
LaResponse is restResponse
vReponseVariant is Variant

MaReq.URL = " [www.cbbh.ba] "
LaResponse = RESTSend(MaReq)

vReponseVariant=JSONToVariant(UTF8ToAnsi(LaResponse.Content))    //JSONVersVariant(UTF8ToAnsi(LaResponse.Content))
sJSon is ANSI string = UTF8ToAnsi(LaResponse.Content)

soit vjs = JSONVersVariant(sJSon)

POUR TOUT _Membre DE vjs..Member
	
	SI _Membre..Membre..Occurrence = 0 ALORS
		Trace("Le membre " + _Membre..Nom + " a la valeur " + _Membre..Valeur)
	SINON
		Trace("Le membre " + _Membre..Nom + " a " + _Membre..Membre..Occurrence + ...
		" autres membres")
		//ParcoursMembresVariant(_Membre)
	FIN
FIN

	PROCEDURE INTERNE ParcoursMembresVariant(x)
	
	POUR TOUT _Membre DE x..Membre
		SI _Membre..Membre..Occurrence = 0 ALORS
			Trace(Répète("--", ChaîneOccurrence(dbgInfo(dbgPile), RC)) + ...
			"Le membre " + _Membre..Nom + " donje sranje " + _Membre..Valeur)
		SINON
			Trace(Répète("--", ChaîneOccurrence(dbgInfo(dbgPile), RC)) + ...
			"Le membre " + _Membre..Nom + " a " + _Membre..Membre..Occurrence + ...
			" autres membres...")
			ParcoursMembresVariant(_Membre)
		FIN
	FIN
	FIN

Error:

Error at line 176 of Click BTN_NoName1 process.
JSONToVariant function called.
Invalid JSON format

----- Technical Information -----

Project : INFOS

WL call:
Process of 'Click BTN_NoName1' (WIN_VISION_VALUTE.BTN_NoName1), line 176, thread 0
'JSONToVariant' function, syntax 0

What happened?
Invalid JSON format

Error code: 40129
Level: fatal error

Dump of the error of 'wd230xml.dll' module (23.0.29.0).
Debugging information:
Fonction (0,325)
Additional Information:
EIT_PILEWL :
Click BTN_NoName1 (WIN_VISION_VALUTE.BTN_NoName1), line 176
Local Procedure Tree_Klik (WIN_MENI.PROCEDURE.Tree_Klik), line 434
Selecting a row of TREE_Robno (WIN_MENI.TREE_Robno), line 2
Click BTN_PRIJAVA (WIN_PRIJAVA.BTN_PRIJAVA), line 27
Exit from EDT_PASWORD (WIN_PRIJAVA.EDT_PASWORD), line 5
Initializing INFOS (), line 274
EIT_DATEHEURE : 01/10/2021 13:11:44
EIT_TYPE_WDFILE : <2>
EIT_IDCODE : <18>

Help

[infosonline.net]



Edited 4 time(s). Last edit at 10/01/2021 01:12PM by infos.
Argus
Re: [WD23] JSONVersVariant (Exemple) ???
October 01, 2021 02:50PM
I'm not sure which line is line 176, but the error message is quite clear: Invalid JSON format


Now, that may be true, or that may be that the json contains something not supported by the function...

So the first thing to do is to :
- get the jSON without transforming it in any way
- DISPLAY the jSON to have a look
- Save the JSON (it's a text file)
- Open it in Notepad++ to see if there is any special char or anything

This should tell you what the problem is.
Re: [WD23] JSONVersVariant (Exemple) ???
October 01, 2021 04:17PM
Thanks Argus for your time

- I forgot to mention that this is an exchange rate list and JSON is as it is on the Bank's website as on the link.
- Is there no possibility to load JSON data directly from the website?

[infosonline.net]
Re: [WD23] JSONVersVariant (Exemple) ???
October 01, 2021 08:24PM
You use this line
MaReq.URL = " [www.cbbh.ba] "

Shouldn't that be
MaReq.URL = "[www.cbbh.ba] "

If I try that the JSONToVariant() does work and in the debugger I can see all the items and values.

Arie
Re: [WD23] JSONVersVariant (Exemple) ???
October 01, 2021 08:28PM
This give me a list of currency exchange rates

sJSON is string
myJSON is Variant

IF HTTPRequest("[www.cbbh.ba]winking smiley THEN
	sJSON = HTTPGetResult()
	Info(sJSON)
	
	myJSON = sJSON
	myJSON = JSONToVariant(sJSON)
	
	Trace(myJSON.Date)
	// Trace(myJSON.Comments) does not work for some reason
	Trace(myJSON.Number)
	Trace(CR)
	
	FOR i = 1 TO myJSON.CurrencyExchangeItems..Occurrence		
		Trace(myJSON.CurrencyExchangeItems.Country)
		Trace(myJSON.CurrencyExchangeItems.NumCode)
		Trace(myJSON.CurrencyExchangeItems.AlphaCode)
		Trace(myJSON.CurrencyExchangeItems.Units)
		Trace(myJSON.CurrencyExchangeItems.Buy)
		Trace(myJSON.CurrencyExchangeItems.Middle)
		Trace(myJSON.CurrencyExchangeItems.Sell)
		Trace(CR)
	END
ELSE
	Error()
END

Arie
Re: [WD23] JSONVersVariant (Exemple) ???
October 01, 2021 11:57PM
Thanks Arie

Yes and my code gives a list and just a list.
When I need to save data then it cannot be retrieved

[infosonline.net]
Re: [WD23] JSONVersVariant (Exemple) ???
October 04, 2021 10:13AM
Greeting


This code solved my problem

Maybe it helps someone else so I’m putting it here

[blogs.pcsoft.fr]

[infosonline.net]
Author:

Your Email:


Subject:


Spam prevention:
Please, enter the code that you see below in the input field. This is for blocking bots that try to post this form automatically. If the code is hard to read, then just try to guess it right. If you enter the wrong code, a new image is created and you get another chance to enter it right.
Message: