Android Question HTTP POST with parameters in custom format

ThePuiu

Active Member
Licensed User
Longtime User
Hello! I want to make a POST call to a server (which I don't control). The call requires a parameter in the form of a string that respects the format:
"[{"param1": "value1"},{ "data": "2023-10-30"}]"


if I try to make the call like this:
Dim parametrii As Map
parametrii.Initialize
parametrii.Put("param1","155810")
parametrii.Put("data","2023-10-30")
j.PostMultipart(destinationUrl,parametrii,Null)

the response from the server is 200 but I receive an error message that the parameters are not in the expected format.

how can i get the required format?
Thank you!
 

walterf25

Expert
Licensed User
Longtime User
Hello! I want to make a POST call to a server (which I don't control). The call requires a parameter in the form of a string that respects the format:



if I try to make the call like this:


the response from the server is 200 but I receive an error message that the parameters are not in the expected format.

how can i get the required format?
Thank you!
I believe you need to send the parameters in JSON format, do a search for Json library and look up examples how to convert a map or a list of maps into Json format.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
that respects the format:
it´s just a json-string


B4X:
Dim parser As JSONParser
parser.Initialize("[{"param1": "value1"},{ "data": "2023-10-30"}]" )
Dim jRoot As List = parser.NextArray
For Each coljRoot As Map In jRoot
 Dim param1 As String = coljRoot.Get("param1")
Next
By checking how to parse such a string you find out that it starts with a LIST. Inside this list are Maps.

If you want to create such go the reverse way

- Create a list
- Add Maps with the content to this list
- Use jsongenerator to create a json out of the List.
- Post this json-string then
 
Last edited:
Upvote 0
Top