org.json.JSONObject and no properties discovered 錯誤解決
阿新 • • 發佈:2018-11-14
自己在搭建SSM框架的時候(Spring + spring mvc + mybatis)報錯內容如下:
No serializer found for class org.json.JSONObject and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS)
報錯的意思是用的這個JSONObject物件由於沒有例項化引起的 !!
導包注意點!(版本隨意 但是包要導正確)
commons-beanutils-1.7.0.jar
commons-collections-3.2.1.jar
commons-lang-2.4.jar
commons-logging-1.1.3.jar
ezmorph-1.0.3.jar
json-lib-2.2.3-jdk15.jar
JSONArray 和 JSONObject 分別是位於以下
import net.sf.json.JSONArray; import net.sf.json.JSONObject;
後端程式碼返回
@ResponseBody @RequestMapping(method = RequestMethod.POST, value = "/loadItems")public JSONArray loadItems(HttpServletRequest request) { int index = Integer.valueOf(request.getParameter("index")); JSONArray json = itemService.loadItemsByIndex(index); System.out.println(json); return json; //返回jsonarray資料 }
前臺AJAX Success函式接收
$.ajax({ type:"post", url:"loadItems", async:"false", data:{ index:1 }, dataType:"json", success:function(data){ alert(data); }, error:function(request) { alert("請求傳送失敗") } })