GROOVY 中对JSON的一些操作

import net.sf.json.JSONArray 
import net.sf.json.JSONObject 
import net.sf.json.JSON 
import net.sf.json.JSONFunction 

def fromList = [1,true,'json'] as JSONArray 
def fromMap = [integer:1, bool: true] as JSONObject 
def strAsJson1 = "{integer:1, bool: true}" as JSON 
def strAsJson2 = "[1,2,3]" as JSON 
def strAsJsonObject = "{integer:1, bool: true}" as JSONObject 
def strAsJsonArray = "[1,2,3]" as JSONArray 
def strAsFunc = "function(param){ this.param = param; }" as JSONFunction 

List list = new ArrayList(); 
list.add( "first" ); 
list.add( "second" ); 
JSONArray jsonArray = JSONArray.fromObject(list); 
return jsonArray 
 

你可能感兴趣的:(groovy)