Dim JSONList As List
JSONList.Initialize
Dim ZeileMap As Map
ZeileMap.Initialize
ZeileMap.put("first_name": "Ali")
ZeileMap.put("last_name": "Adil")
ZeileMap.put("country_code": "974")
ZeileMap.put("mobile": "5514215437")
ZeileMap.put("email": "katt33ah@gmail.com")
ZeileMap.put("created_user_id": 1)
ZeileMap.put("created_time": "2019-04-07T17:41:37.000")
ZeileMap.put("updated_user_id": Null)
ZeileMap.put("updated_time": Null)
ZeileMap.put("pw": "ggg")
ZeileMap.put("is_active": "Y")
JSONList.Add(ZeileMap)
Dim JSONGenerator As JSONGenerator
JSONGenerator.Initialize2(JSONList)
Dim str As String=JSONGenerator.ToString
Dim j As HttpJob
j.Initialize("ghg",Me)
j.PostString("http://192.168.1.12:3000/customers", Array As String("MyJSON", str))
Sub JobDone(Job As HttpJob)
If Job.Success Then
Select Job.JobName
Case "ghg"
Dim res As String
res = Job.GetString
Log(res)
End Select
End If
End Sub
use comma instead of colon, change this line to:ZeileMap.put("first_name": "Ali")
ZeileMap.put("first_name", "Ali")
{"message":"ER_BAD_NULL_ERROR: Column 'first_name' cannot be null"}
B4X:j.PostString("http://192.168.1.12:3000/customers", Array As String("MyJSON", str))
j.PostString("http://192.168.1.12:3000/customers", str)
I tested the same URL with the Postman and was succeeded.This is a message related to your REST API. Nothing related to B4A.
Check your API documentation.
Unfortunately, it did not work.j.PostString("http://192.168.1.12:3000/customers", str)
You should post the exact way you did it with postman.tested the same URL with the Postman and was succeeded
i see your code in post #3 - you throw updated_user_id and updated_time with Null value as parameter while you don't in postman above, maybe you can try to replace Null value with data you use in the postman, is it make changes ?
Not sure how you remove the [ and ]. Instead of parsing as List, you have to parse json from Map.The JSON array formula in Postman begins with { and ends with } as in the picture.
I tried to modify the string and remove [ and ] but was not succeeded.
all my problem is to post the JSON array in the data, because I always get the error:
{"message":"ER_BAD_NULL_ERROR: Column 'first_name' cannot be null"}
Which indicates that the JSON array was not read .
Dim ZeileMap As Map
ZeileMap.Initialize
ZeileMap.put("first_name", "Ali")
ZeileMap.put("last_name", "Adil")
ZeileMap.put("country_code", "974")
ZeileMap.put("mobile", "5514215437")
ZeileMap.put("email", "katt33ah@gmail.com")
ZeileMap.put("created_user_id", 1)
ZeileMap.put("created_time", "2019-04-07T17:41:37.000")
ZeileMap.put("updated_user_id", Null)
ZeileMap.put("updated_time", Null)
ZeileMap.put("pw", "ggg")
ZeileMap.put("is_active", "Y")
Dim JSONGenerator As JSONGenerator
JSONGenerator.Initialize(ZeileMap)
Dim str As String = JSONGenerator.ToString
Dim j As HttpJob
j.Initialize("ghg",Me)
'Log(str)
j.PostString("http://192.168.1.12:3000/customers", str)
My code will generate json string without [ and ] so you do not need to modify my code. Try use my code and see how is it going.I modified the code as you mentioned, and tried to add:
but the problem remained the same.B4X:str=str.Replace("[","") str=str.Replace("]","")