Page 1 of 1

livecode server return json

Posted: Sun Sep 20, 2020 10:48 am
by klamp
Hai,

i am learning livecode mysql queries return json.
how do i do it?

Code: Select all

<?lc
	put "livecodecom" into tDatabaseAddress
	put "runrev_test" into tDatabaseName
	put "runrev_example" into tDatabaseUser
	put "example" into tDatabasePassword

	put revOpenDatabase("MySQL", tDatabaseAddress, tDatabaseName, tDatabaseUser, tDatabasePassword) into tResult
	if tResult is a number then
	put tResult into gConnectionID
	
	put "Table1" into tTableName	-- set this to the name of a table in your database
	put "SELECT * FROM " & tTableName into tSQL
	
	-- query the database
	put revDataFromQuery(tab, cr, gConnectionID, tSQL) into tData
	
	put tData
?>
how do i get tData to return json?

Thanks

Re: livecode server return json

Posted: Sun Sep 20, 2020 11:04 am
by Klaus
Hi klamp,

welcome to the forum!

Hm, you will need to:
1. Create an array from tData
2. Then turn this array to a JSON with -> ArrayToJson(the_array_from_tData) and "put" this.
But on the client or server side, you have to do it this way.


Best

Klaus

Re: livecode server return json

Posted: Sun Sep 20, 2020 11:17 am
by klamp
thank you for answering Klaus

is there any tutorial to convert tDaya to array?
I am still confused.

Re: livecode server return json

Posted: Sun Sep 20, 2020 4:07 pm
by bangkok
klamp wrote:
Sun Sep 20, 2020 11:17 am
is there any tutorial to convert tDaya to array?
Before to try to convert things, you need first to really understand what are arrays...

Here is a good intro :

http://livecode.byu.edu/arrays/introToArrays.php

Re: livecode server return json

Posted: Mon Sep 21, 2020 11:10 am
by klamp
thanks Bangkok.