package org.demo.json;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

/**
 * <p>
 * Json测试
 * </p>
 * 2015年12月29日
 * 
 * @author <a href="http://weibo.com/u/5131020927">Q-WHai</a>
 * @see <a href="http://blog.csdn.net/lemon_tree12138">http://blog.csdn.net/lemon_tree12138</a>
 * @version 0.1
 */
public class JsonDemo {

    public static void main(String[] args) {
        List<String> list = new ArrayList<>();
        list.add("abd");
        list.add("1215");
        JSONArray array = JSONArray.fromObject(list);
        System.out.println(array);
        
        
        
        Map<String, Object> map = new HashMap<>();
        map.put("name", "json");
        map.put("bool", Boolean.TRUE);
        map.put("int", new Integer(1));
        map.put("arr", new String[] { "a", "b" });
        map.put("func", "function(i){ return this.arr[i]; }");
        JSONObject json = JSONObject.fromObject(map);
        System.out.println(json);
        
        
        boolean[] boolArray = new boolean[] { true, false, true };
        JSONArray jsonArray1 = JSONArray.fromObject(boolArray);
        System.out.println(jsonArray1);
        
        
        JSONArray jsonArray3 = JSONArray.fromObject("['json','is','easy']" );
        System.out.println(jsonArray3);
    }
}
