So, I'm receiving from a post method a JSON, like that shown below (a JSON filled with arrays of strings). I receive it in my Java method as a string. My goal is to convert it to a JSONObject and to iterate about it, for example: x.getString("0")
But I have a problem, when I try to convert to a JSONObject, I am using import org.json.JSONObject
, it returns an empty JSONObject like this : {}
Why is it happening ?
Thanks
EDIT: And the string is received with success because if I do return, it returns the JSON I've sent.
{ '0': [ 'Mon Apr 08 2019 19:26:37 GMT+0000 (UTC)' ],
'1': [ '1234', '456', '1234', '456', '1234', '456', '545' ],
'2': [ '1234', '456', '1234', '456', '1234', '456', '545' ],
'3': [ '1234', '456', '1234', '456', '1234', '456', '545' ],
'4': [ '1234', '456', '1234', '456', '1234', '456', '545' ],
'5': [ 'Mon Apr 08 2019 19:30:00 GMT+0000 (UTC)' ] }
// My Java method that converts JSON received to JSONObject:
@POST
@Produces(MediaType.APPLICATION_JSON)
@Path("/{nifCliente}") // irrelevant this part, ignore it, important is the String
public JSONObject inserir (@PathParam("nifCliente")int c, String d) {
JSONObject f = new JSONObject(d)
return f;
}