Come utilizzare il formato JSON per inviare dati sotto forma di tabella ad un server web.
Dim http
As Object, JsonC
As String, JsonV
As String
Set Wba = ActiveWorkbook
Set Fa = Wba.
Sheets("LeggiScrivi")
Fa.Activate
Nc = 3
Nr = 2
'--- intestazioni campi ---
Dim Ci()
As Variant
ReDim Ci(Nc - 1)
For C = 0
To Nc - 1
Ci(C) = Fa.
Cells(5, C + 2)
Next C
'--- Valori ---
Dim Vi()
As Variant
ReDim Vi(Nr - 1, Nc - 1)
For R = 0
To Nr - 1
For C = 0
To Nc - 1
Vi(R, C) = Fa.
Cells(R + 6, C + 2)
Next C
Next R
'--- parametri ---
JsonC = ConvertToJson(Ci)
JsonV = ConvertToJson(Vi)
DataToSend = "Ci=" & JsonC & "&Vi=" & JsonV
'--- chiamata al sito ---
Set http = CreateObject("MSXML2.XMLHTTP")
http.
Open "POST", "http://www.MacroFacili.it/TestJsonInvio.php?R=" & Rnd(), False
http.setRequestHeader "Content-
Type", "application/x-www-form-urlencoded"
http.send DataToSend
'--- risposta del server ---
MsgBox http.responsetext
End Sub