Websdk.serialize: can the jsonitem be a multidimensionnal array?

I’m trying to send a jsonitem to the browser, and it contains a multidimensionnal array
it seems that a single array is ok, but the multidimensionnal array does not go to the browser side…

is it a bug or a feature ?
should I fill a bug report ?

thanks.
@Greg_O_Lone @Anthony_G_Cyphers

if so, can I send the multidim array as a webfile to the browser ?
how to do this ?

Here is the JSON standard. It enables vectors (one dim) but not matrices (mult dim).

You probably need to build a vector of vectors (to make 2 dims), or a vector of vector of vectors to make it 3 dims.

A 2d is like “[[1,2],[3,4]]”

And you can build one as

Var js as new JSONItem("[]")

js.Add( Array(1, 2) )
js.Add( Array(2, 3) )

it’s an array of rows, containing an array of cells. so it’s a vector as you describe it
and in the browser debugger, it does not come through.
I store it in the serialize event “js” class, it does not arrive in the updateControl event in the browser.

if I send a one dimension json array, it arrives into the updateControl event, but not with 2 dims.

Var jsDatas As New JSONItem
Try
  Var rs As RowSet = mDatabase.selectSQL( sqlCode.ToUTF8)
  
  While Not rs.AfterLastRow
    Dim jsRow As New JSONItem
    jsRow.Add rs.Column( pk).IntegerValue
    
    For i As Integer=1 To rs.ColumnCount-1
      jsRow.Add rs.ColumnAt( i).stringValue.toUTF8
    Next i
    
    jsDatas.Add jsRow
    rs.MoveToNextRow
  Wend
  rs.Close
Catch ex As DatabaseException
  Alerte "VNSWebSDKTable.Serialize exception: "+Str(ex.ErrorNumber), ex.Message
End Try

js.Value("dataJson") = jsDatas

jsDatas contains good values (verified using xojo debugger)
js contains good json values
js in the browser updateControl event contains all js items except the jsDatas…

Try something like this

Var jsDatas As New JSONItem("[]")  // Set as array

Try
  
  Var rs As RowSet = mDatabase.selectSQL( sqlCode.ToUTF8)
  
  While Not rs.AfterLastRow
    
    Dim jsRow() As Variant
    
    jsRow.Add rs.Column( pk ).IntegerValue
    
    For i As Integer=1 To rs.ColumnCount-1
      jsRow.Add rs.ColumnAt( i ).stringValue.toUTF8
    Next i
    
    jsDatas.Add jsRow
    rs.MoveToNextRow
    
  Wend
  
  rs.Close
  
Catch ex As DatabaseException
  Alerte "VNSWebSDKTable.Serialize exception: "+Str(ex.ErrorNumber), ex.Message
End Try

js.Value("dataJson") = jsDatas

What do you expect the browser to do with it? Or have you coded that end yourself?

yes I coded it that way, so that I can transfert it to the javascript side and dispatch it there.
(fill a bootstrap table with it)

thanks for this but it still does not get the dataJson to the browser…
Capture d’écran 2021-10-16 à 17.03.52

How are you sending it to the browser? Maybe you have some flaw in that part of the code.

Put this in a web button pressed event. As you can see, it reaches the browser:

Var json as new JSONItem("[]")

json.Add( Array(1, 2) )
json.Add( Array(3, 4) )

// “[ [1, 2] , [3, 4] ]”

// Send it to the browser as a string into a document property called jsData
Me.ExecuteJavaScript("document.jsData='" + json.ToString + "';")

// Let's see if such string reached there
Me.ExecuteJavaScript("alert('It\'s here! : '+document.jsData);")
1 Like

it is for a websdk control. I don’t send it using executejavascript
but with the serialize event of a websdkcontrol.

I will try to send it in a different way.

Can you point out the docs about it? Can’t find it on the docs site.

https://docs.xojo.com/index.php?search=serialize

in the Extra/WebSDK of Xojo folder.

Sad not being in the searchable docs, same for plugin docs.

1 Like

on the good side, it is a quite sparse documentation…

So it probably means it lacks a bit of reorganization and maybe a separated domain concentrating all the related material? Like:

docs.xojo.com
pluginsdk.docs.xojo.com
websdk.docs.xojo.com

if I comment the 3 lines below from my first post, the json gets to the browser !!!

and so a 2 dims array seems to be valid for a websdkcontrol.serialize …

anyway I don’t understand what’s wrong with these 3 lines !

problem lies in :
jsRow.Add rs.ColumnAt( i).stringValue.toUTF8

if I change to :

jsRow.Add "col"+str(i)

then it works.
removing toUTF8 does not remove the problem.
changing ColumnAt with Column does not remove the problem too.

“the truth is elsewhere”

FINALLY found it !
I had to filter for special characters before storing it into the JSONItem
changed ’ to ’
changed " to ".
changed EndofLine to

or your json does not go to the browser !

Forum for Xojo Programming Language and IDE. Copyright © 2021 Xojo, Inc.