課程
/后端開發
/Java
/JSON快速入門(Java版)
jsonobject要提示拋異常
2016-10-02
源自:JSON快速入門(Java版) 3-3
正在回答
其實原因很簡單,看源碼就知道了,源碼中原生put方法這樣寫的:
? public JSONObject put(String key, int value) throws JSONException {
? ? ? ? this.put(key, new Integer(value));
? ? ? ? return this;
? ? }
他自己拋的異常,而傳遞bean去構造一個jsonobject的構造方法只不過是自動創建一個hashMap然后把值注入,不會拋出異常。
傳遞bean的構造方法源碼:
? public JSONObject(Object bean) {
? ? ? ? this();
? ? ? ? this.populateMap(bean);
this()調用的:
? ?public JSONObject() {
? ? ? ? this.map = new HashMap<String, Object>();
+1...
舉報
JSON和GSON的應用,JSON快速入門視頻教程,趕快加入吧
2 回答為什么用 javabean創建json不用toString方法就能打印出結果?
1 回答Android Studio 快速的 生成 javabean 的set 和get 方法
2 回答通過javaBean把java對象轉化為一個Json對象出現沒有傳入javabean對象的構造方法??
2 回答setDateFormat方法有什么用嗎
3 回答使用javaBean 創建JSon 打印String數組是出現"mojor":[{"bytes":[{},{},{},{},{},{}],"empty":false},{"bytes":[{},{},{},{},{},{},{},{},{}],"empty":false}]這樣是什么原因?而用map等其他方法都是正常的,為什么?
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網安備11010802030151號
購課補貼聯系客服咨詢優惠詳情
慕課網APP您的移動學習伙伴
掃描二維碼關注慕課網微信公眾號
2017-04-21
其實原因很簡單,看源碼就知道了,源碼中原生put方法這樣寫的:
? public JSONObject put(String key, int value) throws JSONException {
? ? ? ? this.put(key, new Integer(value));
? ? ? ? return this;
? ? }
他自己拋的異常,而傳遞bean去構造一個jsonobject的構造方法只不過是自動創建一個hashMap然后把值注入,不會拋出異常。
傳遞bean的構造方法源碼:
? public JSONObject(Object bean) {
? ? ? ? this();
? ? ? ? this.populateMap(bean);
? ? }
this()調用的:
? ?public JSONObject() {
? ? ? ? this.map = new HashMap<String, Object>();
? ? }
2016-10-03
+1...