隨筆-9  評論-168  文章-266  trackbacks-0

          一.org.json 解析器 (推薦使用,更適合于對象模型)
          概述及例子: http://code.google.com/p/json-simple/
          API: http://code.google.com/p/json-simple/
          例(測試通過,注意延遲加載問題):
            JSONArray  jsona=new JSONArray();
            JSONObject jsono=new JSONObject();
            List<Author> l=authorDAO.findAll();
            for(Author a:l){
             jsono.put("author_num", a.getAuthorNam());
             jsono.put("author_nam", a.getAuthorNum());
             jsono.put("author_sex", a.getAuthorSex());
             jsono.put("author_level", a.getLevel().getLevelNam());
             jsono.put("author_department", a.getAuthorDepartment());
             jsona.add(jsono.clone());              //jsono.clone()返回實例對象;jsono僅僅只是個指針
             jsono.clear();                                //必須清除內(nèi)容以備下次調(diào)用.
            }

          二.json-lib 解析器
          (1)所需依賴的類文件

          Json-lib requires (at least) the following dependencies in your classpath:

          • jakarta commons-lang 2.3               //appach網(wǎng)站下載最新的
          • jakarta commons-beanutils 1.7.0     //appach網(wǎng)站下載最新的
          • jakarta commons-collections 3.2     //appach網(wǎng)站下載最新的
          • jakarta commons-logging 1.1          //appach網(wǎng)站下載最新的
          • ezmorph 1.0.4

          詳見: http://json-lib.sourceforge.net/

          (2)下載JSON-LIB-2.2.1,并查找 ezmorph 1.0.4 文件

          https://sourceforge.net/project/showfiles.php?group_id=171425

          (3)舉例:

           

           1import net.sf.json.JSONArray;
           2
           3
           4
           5boolean[] boolArray = new boolean[]{true,false,true};      
           6           JSONArray jsonArray1 = JSONArray.fromObject( boolArray );      
           7           System.out.println( jsonArray1 );      
           8           // prints [true,false,true]     
           9              
          10           List list = new ArrayList();      
          11           list.add( "first" );      
          12           list.add( "second" );      
          13           JSONArray jsonArray2 = JSONArray.fromObject( list );      
          14           System.out.println( jsonArray2 );      
          15           // prints ["first","second"]     
          16  
          17           JSONArray jsonArray3 = JSONArray.fromObject( "['json','is','easy']" );      
          18           System.out.println( jsonArray3 );      
          19           // prints ["json","is","easy"]  

          posted on 2008-05-28 16:16 紫蝶∏飛揚↗ 閱讀(4800) 評論(4)  編輯  收藏 所屬分類: JSF 、數(shù)據(jù)轉(zhuǎn)換Json

          評論:
          # re: JSF 與 EXTJS 用 JSON 互傳數(shù)據(jù) 2008-09-30 00:17 | 尋找答案的人
          剩下的哪?就這些?應(yīng)該還有的  回復(fù)  更多評論
            
          # re: JSF 與 EXTJS 用 JSON 互傳數(shù)據(jù) 2008-10-13 14:00 | 紫蝶∏飛揚↗
          這些就足夠了.  回復(fù)  更多評論
            
          # re: JSF 與 EXTJS 用 JSON 互傳數(shù)據(jù) 2008-10-29 18:50 | wpf305
          請教紫蝶∏飛揚↗一個問題:我的有些JSP頁面是一定要帶querystring才能訪問的,在faces-config.xml中配置導航規(guī)則時,卻不能為頁面配置querystring, 那么我又如何從其它頁面中導航到這個頁面時,先這個頁面的頁面Bean設(shè)置有效的值呢?
          請給我講講對于jsf我沒有理解的地方在哪兒。  回復(fù)  更多評論
            
          # re: JSF 與 EXTJS 用 JSON 互傳數(shù)據(jù) 2008-10-29 19:16 | wpf305
          按道理說,在前一個頁面通過outcome導航到后一個頁面時,前一個頁面的頁面bean在后一個頁面渲染期間是可以訪問的,因為同屬于一個request范圍,那么如何訪問前一個頁面bean以獲得一些參數(shù)?  回復(fù)  更多評論
            
          主站蜘蛛池模板: 武穴市| 黎城县| 宝丰县| 虞城县| 郁南县| 于都县| 旺苍县| 潜江市| 和田县| 邹平县| 邯郸市| 高邮市| 通江县| 曲松县| 云龙县| 塔城市| 唐山市| 安平县| 扬州市| 商都县| 南开区| 客服| 达日县| 英吉沙县| 荔波县| 威远县| 东城区| 辉县市| 突泉县| 阳江市| 任丘市| 云阳县| 钦州市| 天水市| 镇江市| 临桂县| 武冈市| 和林格尔县| 黄平县| 盐津县| 香港|