第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

JavaBean轉(zhuǎn)json錯(cuò)誤

JavaBean轉(zhuǎn)json錯(cuò)誤

千萬里不及你 2019-02-25 11:07:20
Document類:public class DocBean {private String docId;private String docName;private String typeId;private String typeName;private String content;private String docTime;private String views;private String cover;} page類public class Page {private int pageNo;private int totalItem;private int pageSize;private String typeId;private List<DocBean> doc=new ArrayList<DocBean>();} 轉(zhuǎn)化代碼:JSONObject page_json=JSONObject.fromObject(page); error:net.sf.json.JSONException: There is a cycle in the hierarchy! at net.sf.json.util.CycleDetectionStrategy$StrictCycleDetectionStrategy.handleRepeatedReferenceAsObject(CycleDetectionStrategy.java:97) at net.sf.json.JSONObject._fromBean(JSONObject.java:833) at net.sf.json.JSONObject.fromObject(JSONObject.java:168) at net.sf.json.AbstractJSON._processValue(AbstractJSON.java:265) at net.sf.json.JSONObject._processValue(JSONObject.java:2808) at net.sf.json.JSONObject.processValue(JSONObject.java:2874) at net.sf.json.JSONObject.setInternal(JSONObject.java:2889) at net.sf.json.JSONObject.setValue(JSONObject.java:1577) at net.sf.json.JSONObject._fromBean(JSONObject.java:934) at net.sf.json.JSONObject.fromObject(JSONObject.java:168) at net.sf.json.JSONObject.fromObject(JSONObject.java:130) at hyit.dataBind.DocBind.initDocList(DocBind.java:124) at hyit.dataBind.DocBind.test01(DocBind.java:132) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) at org.junit.runners.ParentRunner.run(ParentRunner.java:363) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
查看完整描述

6 回答

?
ITMISS

TA貢獻(xiàn)1871條經(jīng)驗(yàn) 獲得超8個(gè)贊

這個(gè)問題,我之前也遇到過:對(duì)象嵌套對(duì)象的情況,不能直接用 JSONObject.fromObject(page) 這方法。
我當(dāng)時(shí)處理的辦法很low。代碼僅供參考:

public static void fromJson(String jsonStr) throws Exception{
        JSONArray jsonArray = JSONArray.fromObject(jsonStr);
        Object[] objs = jsonArray.toArray();
        for (Object object : objs) {
             JSONObject jsonObject = JSONObject.fromObject(object);
             if(jsonObject.has("images")){ // 嵌套的對(duì)象
                  String imgString = jsonObject.getString("images");
                  JSONArray imgArray = JSONArray.fromObject(imgString);
                  Object[] imgObjs = imgArray.toArray();
                  for (Object object2 : imgObjs) {
                    JSONObject jsonObject2 = JSONObject.fromObject(object2);
                    System.out.println(jsonObject2.getString("height")+"\t"+jsonObject2.getString("url"));
                }
             }
             if(jsonObject.has("countrys")){ // 嵌套的對(duì)象
                String countrysString = jsonObject.getString("countrys");
                List<String> stringList = binder.getMapper().readValue(countrysString, List.class);
                System.out.println("String List:");
                for (String element : stringList) {
                    System.out.print(element+"\t");
                }
             }
             System.out.println(jsonObject.getString("offerId")+"\t"+jsonObject.getString("name"));
        }
    }

你也可以選擇百度:java 對(duì)象嵌套 轉(zhuǎn)json

查看完整回答
反對(duì) 回復(fù) 2019-03-01
?
交互式愛情

TA貢獻(xiàn)1712條經(jīng)驗(yàn) 獲得超3個(gè)贊

你可以考慮給每個(gè)變量生成默認(rèn)的get和set方法。

查看完整回答
反對(duì) 回復(fù) 2019-03-01
?
江戶川亂折騰

TA貢獻(xiàn)1851條經(jīng)驗(yàn) 獲得超5個(gè)贊

謝邀。net.sf.json印象中是比較老的一個(gè)包,建議使用jackson和gson。關(guān)鍵字可以搜索google:

  • jackson object to json

  • gson object to json

查看完整回答
反對(duì) 回復(fù) 2019-03-01
?
一只萌萌小番薯

TA貢獻(xiàn)1795條經(jīng)驗(yàn) 獲得超7個(gè)贊

net.sf.json.JSONObject jsonObject = net.sf.json.JSONObject.fromObject(JsonStr);
Map<String, Class> classMap = new HashMap<String, Class>();
classMap.put("selectInfo", SelectPropsDto.class);
classMap.put("checkBoxInfo", CheckPropsDto.class);
classMap.put("radioInfo", RadioPropsDto.class);
GoodsDto goods = (GoodsDto) net.sf.json.JSONObject.toBean(jsonObject, GoodsDto .class,classMap);

多看看文檔!希望能幫到你

查看完整回答
反對(duì) 回復(fù) 2019-03-01
  • 6 回答
  • 0 關(guān)注
  • 512 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)