Dim data As List
data.Initialize
data.Clear
For xx = 0 To 10' Contactz.Size-1
data.Add(CreateMap("name": xx, "mobile": xx))
Next
JSONGenerator.Initialize2(data)
Log (JSONGenerator.ToPrettyString(1))
resp.Write(JSONGenerator.ToPrettyString(1))
Can I ask for help with this? This is what I want the json output
B4X:
{
"message": "The data you provided is invalid.",
"error": [
{
"platform": "platform is required."
},
{
"version": "version is required."
}
],
"status": 422
}
here's my code
B4X:
Dim paramsList As List
paramsList.Initialize
For Each paramsValue As String In Array(platform, version)
If paramsValue = "" Then
paramsList.Add(CreateMap(paramsValue : $"${paramsValue} is required."$))
End If
Next
If paramsList.Size <> 0 Then
Dim error As Map = CreateMap("status":422,"message":"The data you provided is invalid.","error": paramsList)
JSONGenerator.Initialize(error)
resp.Write(JSONGenerator.ToPrettyString(1))
end if
and this is the output
B4X:
{
"message": "The data you provided is invalid.",
"error": [
{
"": " is required."
},
{
"": " is required."
}
],
"status": 422
}
How can I get the "platform" and "version" and add it in json output so I can achieve the output from the top json output?
Dim ParamsList As List
ParamsList.Initialize
For Each paramsValue As String In Array("version", "platform")
Dim m As Map = CreateMap(paramsValue : $"${paramsValue} is required."$)
ParamsList.Add(m)
Next
Dim Error As Map = CreateMap("status" : 422, "message" : "The data you provided is invalid.", "error": ParamsList)
Log(Error.As(JSON).ToString)
Dim ParamsList As List
ParamsList.Initialize
For Each paramsValue As String In Array("version", "platform")
Dim m As Map = CreateMap(paramsValue : $"${paramsValue} is required."$)
ParamsList.Add(m)
Next
Dim Error As Map = CreateMap("status" : 422, "message" : "The data you provided is invalid.", "error": ParamsList)
Log(Error.As(JSON).ToString)