使用json
时出现此异常 json: com.thetransactioncompany.jsonrpc2.JSONRPC2ParseException: Invalid JSON-RPC 2.0:
缺少版本字符串? 我在以下行获得例外:
JSONRPC2Response response = session.send(requestOut);
这是我的代码:
JSONRPC2Session session = new JSONRPC2Session(endPointURL);
JSONRPC2SessionOptions options=session.getOptions();
///options.setRequestContentType("text/html");
options.setAllowedResponseContentTypes(new String[]{"text/html; charset=UTF-8"});
String method = "Request";
String timestamp=PaymentStringUtil.gofTimeStamp();
Map<String, Object> reqParams = new HashMap<String, Object>();
reqParams.put("words", StringUtil.sha1("SA3PROU","a8affe42f8bbc90621762c53fd973bceee175db2","20140120100821"));
reqParams.put("tourcode", "SA3PROU");
reqParams.put("timestamp","20140120100821");
System.out.println(reqParams);
JSONRPC2Request requestOut = new JSONRPC2Request(method,reqParams,1);
System.out.println(requestOut);
try {
System.out.println("Inside try-----------");
JSONRPC2Response response = session.send(requestOut);
//System.out.println(session.send(requestOut));
System.out.println(response.indicatesSuccess());
if (response.indicatesSuccess()) {
System.out.println("Inside the indicate success");
JSONParser jsonParser =new JSONParser();
JSONObject jsonObject=(JSONObject)jsonParser.parse(response.getResult().toString());
JSONObject response=(JSONObject)jsonObject.get("Request");
//set the response obj
} else {
System.out.println("Outside the indicate success");
System.out.println(response.getError().getMessage());
}
} catch (Exception e) {
System.out.println(e.getMessage());
e.printStackTrace();
}
return response;
}
这是堆栈跟踪:
无效的JSON-RPC 2.0响应 com.thetransactioncompany.jsonrpc2.client.JSONRPC2SessionException:无效的JSON-RPC 2.0响应 在com.thetransactioncompany.jsonrpc2.client.JSONRPC2Session.send(JSONRPC2Session.java:586) 在com.garuda.api.test.Configure.requestProvider(Configure.java:81) 在com.garuda.api.test.Configure.main(Configure.java:128) 引起:com.thetransactioncompany.jsonrpc2.JSONRPC2ParseException:无效的JSON-RPC 2.0:缺少版本字符串 在com.thetransactioncompany.jsonrpc2.JSONRPC2Parser.ensureVersion2(JSONRPC2Parser.java:236) at com.thetransactioncompany.jsonrpc2.JSONRPC2Parser.parseJSONRPC2Response(JSONRPC2Parser.java:481) 在com.thetransactioncompany.jsonrpc2.JSONRPC2Response.parse(JSONRPC2Response.java:229) 在com.thetransactioncompany.jsonrpc2.client.JSONRPC2Session.send(JSONRPC2Session.java:579) ......还有2个
答案 0 :(得分:1)
查看source code of JSONRPC2Parser JSON-RPC 2.0的版本必须存在于jsonrpc成员的请求对象中。如果它根本不存在,则会得到您描述的错误。根据{{3}},版本必须存在且为2.0
。