반응형
package com.lsj.chatting;

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

import org.json.JSONArray;
import org.json.JSONObject;

public class testing {

	public static void main(String[] args) {

		Map<String,Object> map = new HashMap<String,Object>();
		List<String> hobbies = new ArrayList<String>();
		hobbies.add("cook");
		hobbies.add("shopping");
		
		map.put("name", "brown");
		map.put("hobbies", hobbies);
		
		System.out.println(map);
		
		JSONObject mapJson = new JSONObject(map);
		System.out.println(mapJson);
		
		// {hobbies=[cook, shopping], name=brown}
		// {"hobbies":["cook","shopping"],"name":"brown"}
		
		JSONArray hobbiesJsonArray = new JSONArray(hobbies);
		System.out.println(hobbiesJsonArray);
		
		// ["cook","shopping"]
		
	}
	
}
반응형