由于框架是用的Simplejson,找了半天都没找着如何将字符串转化为对象的方法, 后来发现以前写过,找了半天,找到了JSONValue.parse("jsondata"),可以将JSON字符串转化为所需要的对象。

/* * @version $Id$ * * Copyright (c) 2009-2010 yellowcong */
package com.yellowcong.dao;

import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.JSONValue;

/** * JSONTest。 * * * * @version $Id$ */
public class JSONTest {
      
        
    public static void main(String [] args){

        JSONObject result = new JSONObject();

        result.put("pageSize", "12");
        JSONArray rows = new JSONArray();
        for(int i=0;i<10;i++){
            JSONObject row = new JSONObject();
            row.put("username", "yellowcong");
            row.put("age", "23");
            row.put("sex", "男");
            row.put("email", "717350389@qq.com");

            rows.add(row);
        }
        result.put("gridData", rows);

        //将JSOn对象转化为String 对象
        String jsonStr = result.toJSONString();
        System.out.println(jsonStr);


        //将String类型转化为JSON
        JSONObject resultPrase = (JSONObject) JSONValue.parse(jsonStr);
        System.out.println("转化后\t"+resultPrase.get("pageSize"));

    }
}