package com.lei.test;
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;
public class JSONTest {
public static void main(String argsp[]) {
List<String> list = new ArrayList<String>();
list.add("first");
list.add("second");
JSONArray jsonArray2 = JSONArray.fromObject(list);
Map<String, String> map = new HashMap<String, String>();
map.put("name", "sad");
map.put("age", "2343");
map.put("list", list.toString());
JSONObject jsonObject = JSONObject.fromObject(map);
System.out.println(jsonObject.toString());
System.out.println(jsonArray2.toString());
String s = new String("{\"name\":\"zxc\",\"age\":21}");
JSONObject jsonObject2 = JSONObject.fromObject(s);
String s2 = new String("[\"nihao\",\"wohenhao\"]");
JSONArray jsonArray1 = JSONArray.fromObject(s2);
System.out.println(jsonArray1.toString());
System.out.println(jsonObject2.toString());
}
}
JSONObject 和JSONArray 方法测试
最新推荐文章于 2020-05-28 10:31:28 发布