在游戏框架中获得 json
get json in play-framwork
我想从 angularJS 应用程序中使用我的播放框架 application() 获取 json 字符串。
这是我实际发送的:
{"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"}
]
}:""
我总是收到状态代码 500(内部服务器错误)。
可能我的路线中有些不正确吗?
路线:
POST /networkInsertJson controllers.NetworkController.InsertJson()
json 字符串的最后 3 个字符可能有问题吗?
这是我的控制器:
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);
}
你能帮我找出错误吗?
我在这些行中发现了自己的错误:
result.put("in", ins.toJSONString());
我试图插入一个数组作为 json 元素的内容。
我想从 angularJS 应用程序中使用我的播放框架 application() 获取 json 字符串。
这是我实际发送的:
{"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"}
]
}:""
我总是收到状态代码 500(内部服务器错误)。 可能我的路线中有些不正确吗? 路线:
POST /networkInsertJson controllers.NetworkController.InsertJson()
json 字符串的最后 3 个字符可能有问题吗?
这是我的控制器:
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);
}
你能帮我找出错误吗?
我在这些行中发现了自己的错误:
result.put("in", ins.toJSONString());
我试图插入一个数组作为 json 元素的内容。