[英]How to pass in android a RPC Json with nested parameters
What is the right code to pass a json with nested parameters in this form 在此表单中使用嵌套参数传递json的正确代码是什么
{"method":"startSession",
"params": [ "email": "testmail@test.it",
"password": "1234",
"stayLogged": "1",
"idClient": "ANDROID"
]
}
to a webservice URL that receive RPC?? 到接收RPC的webservice URL?
the webservice code is Web服务代码是
@Webservice(paramNames = {"email", "password", "stayLogged", "idClient"},
public Response startSession(String email, String password, Boolean stayLogged, String idClient) throws Exception {
boolean rC = stayLogged != null && stayLogged.booleanValue();
UserService us = new UserService();
User u = us.getUsersernamePassword(email, password);
if (u == null || u.getActive() != null && !u.getActive().booleanValue()) {
return ErrorResponse.getAccessDenied(id, logger);
}
InfoSession is = null;
String newKey = null;
while (newKey == null) {
newKey = UserService.md5(Math.random() + " " + new Date().getTime());
if (SessionManager.get(newKey) != null) {
newKey = null;
} else {
is = new InfoSession(u, rC, newKey);
if (idClient != null && idClient.toUpperCase().equals("ANDROID")) {
is.setClient("ANDROID");
}
SessionManager.add(newKey, is);
}
}
logger.log(Level.INFO, "New session started: " + newKey + " - User: " + u.getEmail());
return new Response(new InfoSessionJson(newKey, is), null, id);
}
I'm going to assume you are using json-rpc 1.0 as there is no version indicator in your request. 我将假设您使用的是json-rpc 1.0,因为您的请求中没有版本指示器。
First your missing your "id", so add that to the request. 首先你想念你的“id”,所以把它添加到请求中。
Now here are 3 different things you could try. 现在,您可以尝试3种不同的东西。
1) You need to use an object {} instead of array [] if you are going to set name and value pairs. 1)如果要设置名称和值对,则需要使用对象{}而不是array []。 Like:
喜欢:
{"method":"startSession",
"params": { "email": "testmail@test.it",
"password": "1234",
"stayLogged": "1",
"idClient": "ANDROID"
},
"id":100
}
2) If your json deserializer is requiring the array syntax [] then you may have to wrap your object {} in [] like: 2)如果你的json反序列化器需要数组语法[],那么你可能需要在[]中包装你的对象{},如:
{"method":"startSession",
"params": [{ "email": "testmail@test.it",
"password": "1234",
"stayLogged": "1",
"idClient": "ANDROID"
}],
"id":101
}
3) Finally, you could also try using positional params just in an array like: 3)最后,您还可以尝试在数组中使用位置参数:
{"method":"startSession",
"params": [ "testmail@test.it",
"1234",
"1",
"ANDROID"
],
"id":102
}
Hope that helps. 希望有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.