Android Question Map2Array

Mashiane

Expert
Licensed User
Longtime User
Hi

How can I achieve a Map2ArrayOfString function. I want to convert a map to an array of string. For example for use in...

B4X:
Job1.Download2("http://www.xxxx.yyy/register/register.php", _
      Array As String("Action", "CheckRegister", "Imei", imei, "Mail", RegMail.Text))

I want to create a method that will return the Array As String from a map.
 

KMatle

Expert
Licensed User
Longtime User
You can get the key/values from the map (it's the same as "Action" =key and "CheckRegister" = value) with

B4X:
For c = 0 To MyMap.Size - 1
             Dim key, value As String
             key = MyMap.GetKeyAt(c)
             value = MyMap.GetValueAt(c)
Next

Better: Send that map :D which is an array

B4X:
    Dim MyMap as Map

    MyMap.Initialize

    MyMap.put("Action", "CheckRegister")
    MyMap.put("Imei", imei)
    MyMap.put("Maill", RegMail.Text)
    
   
    Dim JSONGenerator As JSONGenerator
    JSONGenerator.Initialize2(MyMap)
   
    Dim JSONstring As String
    JSONstring = JSONGenerator.ToString
    MyLog(JSONstring)
   
    Dim Register As HttpJob
         Register.Initialize("Register", Me)
        Register.PostString("http://www.xxxx.yyy/register/register.php",JSONstring)

On the php side:

B4X:
$json = array();
$json = file_get_contents("php://input");

$action=$json["Action"]

etc.
 
Upvote 0

Mashiane

Expert
Licensed User
Longtime User
You can get the key/values from the map (it's the same as "Action" =key and "CheckRegister" = value) with

B4X:
For c = 0 To MyMap.Size - 1
             Dim key, value As String
             key = MyMap.GetKeyAt(c)
             value = MyMap.GetValueAt(c)
Next

Better: Send that map :D which is an array

B4X:
    Dim MyMap as Map

    MyMap.Initialize

    MyMap.put("Action", "CheckRegister")
    MyMap.put("Imei", imei)
    MyMap.put("Maill", RegMail.Text)
   
  
    Dim JSONGenerator As JSONGenerator
    JSONGenerator.Initialize2(MyMap)
  
    Dim JSONstring As String
    JSONstring = JSONGenerator.ToString
    MyLog(JSONstring)
  
    Dim Register As HttpJob
         Register.Initialize("Register", Me)
        Register.PostString("http://www.xxxx.yyy/register/register.php",JSONstring)

On the php side:

B4X:
$json = array();
$json = file_get_contents("php://input");

$action=$json["Action"]

etc.
Thanks...
 
Upvote 0
Top