I want to get a json string with my play-framework application() from a angularJS application.
This is what I actually send:
{"in":[
{"id":4,"ip":"192.168.0.20","pinSysNo":4,"pinSysName":"pg6","folderName":"gpio4_pg6","alias":"d","direction":"digital_in"},
{"id":3,"ip":"192.168.0.20","pinSysNo":3,"pinSysName":"pb18","folderName":"gpio3_pb18","alias":"c","direction":"digital_out"}
],
"out":[
{"id":1,"ip":"192.168.0.20","pinSysNo":1,"pinSysName":"pg3","folderName":"gpio1_pg3","alias":"a","direction":"digital_in"},
{"id":2,"ip":"192.168.0.20","pinSysNo":2,"pinSysName":"pb16","folderName":"gpio2_pb16","alias":"b","direction":"digital_in"}
]
}:""
I always get the status code 500(internal server error). May some in my routes are not correct? routes:
POST /networkInsertJson controllers.NetworkController.InsertJson()
May do I have a problem with the last 3 chars from the json string?
This is my Controller:
public static Result InsertJson(){
ObjectNode result = Json.newObject();
JsonNode json = request().body().asJson();
org.json.simple.parser.JSONParser parser = new JSONParser();
JSONObject o = new JSONObject();
try{
o = (JSONObject) parser.parse(json.asText());
}catch (Exception e){
}
JSONArray ins = (JSONArray) o.get("in");
JSONArray outs = (JSONArray) o.get("out");
//I return the json back for testing
result.put("in", ins.toJSONString());
return ok(result);
}
Could you help me to find the mistake?
I found my own mistake in these line :
result.put("in", ins.toJSONString());
I tried to insert an array as the content of an json element.