java 基础常用的 方法(一)

2014-11-24 08:39:19 · 作者: · 浏览: 0
zejun.zhou zejun.zhou11
// List listValue = null;
//
// for (int i = 0; i < 10; i++) {
// listValue = new ArrayList();
// testEX test = new testEX();
//
// listValue.add(test.getIi() + "dd" + i);
// map.put(test.getIi() + "dd" + i, listValue);
// }
// // for (int i = 0; i < map.size(); i++) {
// List time = new ArrayList();
// // List listKey = new ArrayList();
// List listValue1 = new ArrayList();
// Iterator it = map.keySet().iterator();
// while (it.hasNext()) {
// String key = it.next().toString();
// System.out.println(key);
// time = (List) map.get(key);
// // output the context of the ArrayList
// for (int k = 0; k < time.size(); k++) {
// System.out.println(map.get(key));
// System.out.println(time.get(k));
// }
// }
//
http://172.16.2.123/zentao/user-login-L3plbnRhby8=.html
http://www.jb51.net/books/86021.html
http:// www.linuxidc.com/Linux/2011-12/49516p2.htm
一、json 必须包
commons-collections-3.2.jar
commons-lang-2.3.jar,
commons-beanutils-1.7.0.jar,
ezmorph-1.0.4.jar
commons-logges
导入这些包试试 一般用了这几个就可以了
commons-beanutils.jar,
commons-httpclient.jar,
commons-lang.jar,
ezmorph.jar,
morph-1.0.1.jar
map 转json
Json json=new Json(); // new 一个对象
json.setName("地方");
json.setSex("的风格");
Json json1=new Json();
json1.setName("飞");
json1.setSex("飞");
Map list=new HashMap();
list.put("json",json);
list.put("json1",json1);
JSONObject json111= JSONObject.fromObject(list); // 转换成jsonobject
JSONObject name1=json111.getJSONObject("json"); // 获取jsonobject
String names=name1.getString("name"); // 从jsonobject 中取值
字符串转jsonobject
String str = "{'string':'JSON','integer':1,'double':2,'boolean':true}";
JSONObject jsonObject1 = (JSONObject) JSONSerializer.toJSON(str);
// jsonobject 和jsonarray的活用
JSONObject jsonObject = new JSONObject();// jsonobject 和jsonarray的活用
JSONObject jsonObject1 = new JSONObject();
jsonObject1.element("name", "1");
JSONArray jsonArray=new JSONArray();
jsonArray.add("1");
jsonObject1.element("money", jsonArray);
JSONObject jsonObject2 = new JSONObject();
jsonObject2.element("name", "2");
JSONArray jsonArray2=new JSONArray();
jsonArray2.add("2");
jsonObject2.element("money", jsonArray2);
jsonObject.element("jsonObject1",jsonObject1);
jsonObject.element("jsonObject2",jsonObject2);
JSONObject json1=jsonObject;
JSONObject json2= json1.getJSONObject("jsonObject1");
String name=json2.getString("name");
String sex=json2.getString("sex");
JSONArray jsonArray1 = json2.getJSONArray("money");
String money=(String)jsonArray1.get(0);
二、字符串
String.valueOf(int); // int 转化成String
indexOf() 包含。>=0 否则为-1
三、创建xml
soap.jar
import org.apache.soap.util.xml.XMLParserUtils;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import javax.xml.parsers.DocumentBuilder;
DocumentBuilder xdb = XMLParserUtils.getXMLDocBuilder();
Document doc = xdb.newDocument();