JSONObject某些常用方法

JSONObject response=new new JSONObject(); //括号内加true可以对内部进行排序response.clear();  //清除内容//将map转换成jsonobject,其中map为map类型:JSONObject records=new JSONObject(map);//JSON形式字符串转nutmapString result = testFeignRemote.queryResult(requestStr);map = new NutMap(result);  或者          map=JSON.parseObject(result ,NutMap.class); //map先转json串再转成json对象NutMap responseMap = changeResponse(map);String jsonString = JSON.toJSONString(responseMap);response = JSONObject.parseObject(jsonString);Map<String, Object> messageMap = JSON.parseObject(String.valueOf(message), Map.class);有不同的json解析包,但用法大同小异,注意其中方法的写法区别。例如:fastjson与sf.json,sf.json依赖时注意事项:<dependency>    <groupId>net.sf.json-lib</groupId>    <artifactId>json-lib</artifactId>    <version>2.4</version>    <classifier>jdk15</classifier></dependency>如果classifier不写的话可能会出错。intValue()方法可用来获取BigInt值的int值科普向:JSONObject-lib包是一个beans,collections,maps,java arrays和xml和JSON互相转换的包。构造方法如下:JSONObject();创建一个空的JSONObject对象JSONObject(boolean isNull);创建一个是否为空的JSONObject对象普通方法如下:fromBean(Object bean);静态方法,通过一个pojo对象创建一个JSONObject对象fromJSONObject(JSONObject object);静态方法,通过另外一个JSONObject对象构造一个JSONObject对象fromJSONString(JSONString string);静态方法,通过一个JSONString创建一个JSONObject对象toString();把JSONObject对象转换为json格式的字符串iterator();返回一个Iterator对象来遍历元素接下来就是一些put/get方法,需要普通的get方法和pot方法做一下强调说明,API中是这样描述的:A get method returns a value if one can be found, and throws an exception if one cannot be found. An opt method returns a default value instead of throwing an exception, and so is useful for obtaining optional values. JSONArray:A JSONArray is an ordered sequence of values.是一个final类,继承了Object,实现了JSON接口构造方法如下:JSONArray();构造一个空的JSONArray对象普通方法如下:fromArray(Object[] array);静态方法,通过一个java数组创建一个JSONArray对象fromCollection(Collection collection);静态方法,通过collection集合对象创建一个JSONArray对象fromString(String string);静态方法,通过一个json格式的字符串构造一个JSONArray对象toString();把JSONArray对象转换为json格式的字符串iterator();返回一个Iterator对象来遍历元素接下来同样是put/get方法……XMLSerializer:Utility class for transforming JSON to XML an back.一个继承自Object的类构造方法如下:XMLSerializer();创建一个XMLSerializer对象普通方法如下:setRootName(String rootName);设置转换的xml的根元素名称setTypeHintsEnabled(boolean typeHintsEnabled);设置每个元素是否显示type属性write(JSON json);把json对象转换为xml,默认的字符编码是UTF-8,需要设置编码可以用write(JSON json, String encoding)

JSONObject某些常用方法

Windows/Linux根据端口结束进程与根据端口找到程序位置

根据端口结束进程:先查询出端口获得pid,随后结束pidwindows:netstat -ano|findstr 8081taskkill /f /pid 17048linux根据端口查询程序位置:netstat -antlp|grep 9002 根据端口查询获取pidcd /proc/12093 进入pidcwd->                           获取位置或者:pwdx 12093                      pwdx加进程号亦可