<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    自身一對多關聯模型的JSON轉換

           最近又遇到了一個問題, 這里有一個一對多自身關聯的模型
     1Class Tree
     2{
     3   private String id;
     4   private String name;
     5   private Set<tree> children = new HashSet<Tree>();
     6   public void setId(String id)
     7   {
     8         this.id = id;
     9   }

    10   public String getId()
    11   {
    12         return this.id;
    13   }

    14    
    15}
    然后我用JSON把這個模型轉換成string的時候會報錯:will throw a JSONException if a cycle is found.后來去查了下JSON的API發現是我的JSON轉換策略有問題。原文是這樣的:
    public abstract class CycleDetectionStrategy
    extends Object
    
    

    Base class for cycle detection in a hierarchy.
    The JSON spec forbides cycles in a hierarchy and most parsers will raise and error when a cycle is detected. This class defines a contract for handling those cycles and two base implementations:

    • STRICT - will throw a JSONException if a cycle is found.
    • LENIENT - will return an empty array or null object if a cycle is found.

    說的很清楚了所以必須做點修改像這樣:
     1public class TreeAction extends BaseActionSupport{
     2    private static final CycleDetectionStrategy CycleDetectionStrategy = null;
     3    public String getAllTree()
     4    {
     5        JsonConfig jsonConfig=new JsonConfig();
     6        jsonConfig.setCycleDetectionStrategy(CycleDetectionStrategy.LENIENT);
     7        tree = regionService.getTreeChildren("402881821a7fbf10011a7fc2d3ae0001");
     8        JSONObject array = JSONObject.fromObject(tree,jsonConfig);
     9        System.out.println("$$$$$$$$$$"+array.toString()+"$$$$$$$$$$$$$$");
    10        return SUCCESS;
    11    }

    12}

    這樣修改以后轉換就正常啦~~~。呵呵,HIBERNATE還有好多問題我沒解決煩惱中。。。。。。


    posted on 2008-06-20 22:59 Cloud kensin 閱讀(1084) 評論(0)  編輯  收藏 所屬分類: Java

    <2008年6月>
    25262728293031
    1234567
    891011121314
    15161718192021
    22232425262728
    293012345

    導航

    統計

    常用鏈接

    留言簿(4)

    隨筆分類

    相冊

    相冊

    搜索

    最新評論

    主站蜘蛛池模板: 午夜两性色视频免费网站| 四虎影视在线永久免费看黄| 亚洲一本一道一区二区三区| 亚洲欧洲自拍拍偷精品 美利坚| 久久精品一本到99热免费| 亚洲狠狠婷婷综合久久蜜芽| 亚洲一区二区女搞男| 91成人免费观看网站| 日韩在线视频播放免费视频完整版 | 亚洲精品无码Av人在线观看国产| ww在线观视频免费观看| 欧洲亚洲综合一区二区三区| 久久久无码精品亚洲日韩京东传媒 | 两个人日本WWW免费版 | 久久久久久毛片免费播放| 国产99久久亚洲综合精品| 亚洲日本一区二区| mm1313亚洲精品无码又大又粗| 精品无码人妻一区二区免费蜜桃| 美女免费视频一区二区三区| 亚洲网址在线观看| 中文字幕日韩亚洲| 情侣视频精品免费的国产| 无码国产精品一区二区免费式芒果 | 久久乐国产精品亚洲综合| 国产精品无码免费播放| 久久国产精品成人免费| 日日躁狠狠躁狠狠爱免费视频| 亚洲国产中文在线二区三区免| 国产AV无码专区亚洲AWWW| 日韩免费在线观看| 无码国产精品一区二区免费虚拟VR| 成人A毛片免费观看网站| 青草久久精品亚洲综合专区| 亚洲宅男天堂a在线| 国产成A人亚洲精V品无码 | 亚洲精品福利在线观看| 亚洲中文字幕无码日韩| 亚洲成?v人片天堂网无码| 四虎在线视频免费观看| 日本免费一区二区在线观看|