Android Question Invalid JSON with PUT in httputils

bluedude

Well-Known Member
Licensed User
Longtime User
Hi,

I adapted the methods used in httputils to also work with PUT, DELETE etc. However, I face some problems with json payloads and PUT statements.

When using below JSON it gives me "Could not parse invalid json":

{
"field1":"test"
}

This is what I do:

jsonMap.Put ("field1","test")
jsonList.Add (jsonMap)
json.Initialize2 (jsonList)
jsonData = json.ToPrettyString(2)
jsonData = jsonData.Replace ("[","")
jsonData = jsonData.Replace ("]","")

httpPUT.Initialize ("httpPUTResult",Me)
httpPUT.PutString ("some api url",jsonData)
httpPUT.GetRequest.SetContentType("application/json")

HTTPUtils method
Public Sub PutString(Link As String, Text As String)
PutBytes(Link, Text.GetBytes("UTF8"))
End Sub

Public Sub PutBytes(Link As String, Data() As Byte)
req.InitializePut2(Link, Data)
CallSubDelayed2(HttpUtils2Service, "SubmitJob", Me)
End Sub

I cannot share the API I use but it is a default REST interface that works with PUT and DELETE.
 

sirjo66

Well-Known Member
Licensed User
Longtime User
You can't use
B4X:
{
"field1":"test"
}
but you need to use it without CRLF:
B4X:
{"field1":"test"}

so, don't use json.ToPrettyString but json.ToString

Sergio
 
Upvote 0
Top