获取空指针异常JSON AJAX / Servlet 调用以下servlet的Ajax post调用
$.ajax({
url: '/bin/commersenext/assetUpload',
type: 'POST',
contentType:'application/json',
data: JSON.stringify(ob),
dataType: 'json',
success:function(msg){
alert("data"+msg);
console.log(msg);
}
});
Servlet代码 - 发生nullpointerexception的地方:
JSONParser parser = new JSONParser();
JSONArray jsonArray = null;
String tabledata = request.getParameter("data");
try{
Object obj = parser.parse(tabledata);
JSONArray array = (JSONArray)obj;
System.out.println(array.get(1));
答案 0 :(得分:0)
尝试将此条件放入您的代码中。
if(data.status == 0){
var value = JSON.parse(data.data);
console.log("data saved");
return;
}
答案 1 :(得分:0)
BufferedReader br = new BufferedReader(new InputStreamReader(request.getInputStream()));
String json = "";
if(br != null){
json = br.readLine();
System.out.println(json);
}
它现在正在工作.. !!!