博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
备用java方法
阅读量:6949 次
发布时间:2019-06-27

本文共 1219 字,大约阅读时间需要 4 分钟。

1,

Java代码  
  1.     public static JsonRpcRequest getJsonRpcRequest(Map<String, Object> map) {  
  2.         JsonRpcMethod rpcMethod = new JsonRpcMethod();  
  3.         rpcMethod.setMethod("");  
  4.         rpcMethod.setParams(map);  
  5.   
  6.         List<JsonRpcMethod> methodList = new ArrayList<JsonRpcMethod>();  
  7.         methodList.add(rpcMethod);  
  8.   
  9.         JsonRpcRequest rpcReq = new JsonRpcRequest();  
  10.         rpcReq.setRequest(methodList);  
  11.         return rpcReq;  
  12.   
  13.     }  
  14.   
  15.       
  16. }  

 

 

2,把json字符串转化为Map

Java代码  
  1. /*** 
  2.      * convert json string to Map;e.g:{errorMessage=系统异常,请稍后再试!, id=, status=02, errorCode=error_default, method=} 
  3.      * @param jsonResult 
  4.      * @return 
  5.      * @throws UnsupportedEncodingException 
  6.      * @throws JSONException 
  7.      * @throws org.json.JSONException 
  8.      */  
  9.     public static Map<String, String> getMap(String jsonResult)  
  10.             throws UnsupportedEncodingException, JSONException,  
  11.             org.json.JSONException {  
  12.         Map<String, String> resultMap =null;  
  13.         Map obj = (Map) JsonParser.parserRandomJsonFormat(jsonResult);  
  14.         if (ValueWidget.isNullOrEmpty(obj)) {  
  15.             return null;  
  16.         }  
  17.         List resultList = (List) obj.get("resultList");  
  18.         if(ValueWidget.isNullOrEmpty(resultList)){  
  19.             resultMap=obj;  
  20.         }else{  
  21.             resultMap= new HashMap<String, String>();  
  22.             for (int i = 0; i < resultList.size(); i++) {  
  23.                 Map mp_tmp = (Map) resultList.get(i);  
  24.                 parseMap(resultMap, mp_tmp);  
  25.             }  
  26.         }  
  27.           
  28.         return resultMap;  
  29.   
  30.     }  

 

转载地址:http://kiyil.baihongyu.com/

你可能感兴趣的文章
运维基础--虚拟机的使用(一)
查看>>
linux高级安全ssh限制利用PAM
查看>>
ocp007 题库解析(1-15)
查看>>
spring mybatis使用时报 java.lang.AbstractMethodError
查看>>
mui ajax请求 登录
查看>>
我的友情链接
查看>>
fir.im Weekly - 2016 年 Android 最佳实践列表
查看>>
异步消息的性能与激情之Netty开发思路
查看>>
我的友情链接
查看>>
Gradle与Makefile构建工具的对比
查看>>
我的友情链接
查看>>
poi导出的excel不能超过256列
查看>>
基于etcd+confd通过nginx对docker服务混合注册发现详解
查看>>
apt-get install
查看>>
JVM中也有并发GC,CMS机制
查看>>
maven的坐标
查看>>
SpringBoot集成MyBatis
查看>>
读JDK动态代理源码(Proxy类)
查看>>
tuple操作、dict、其他常用操作
查看>>
dubbo入门级梳理
查看>>