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());
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。