我有一个应用程序,我使用this link调用了webservice,我有一个web服务Url,而另一个Url正在从该url获取响应。我需要使用该URL作为
public static final String TIME_CENTRAL_SERVER =“http://accounts.myexample.com/Services”;代替 “http://accounts.myexample.com/Services”我需要解析我的json回复。
我已经在谷歌检查了但是无法得到任何答案,任何人都可以帮我解决这个问题,在此先感谢。 如果有人有疑问问我。
答案 0 :(得分:0)
第一个webservice调用如下所示
RestClient client = new RestClient(LOGIN_URL);
client.AddParam("accountType", "GOOGLE");
client.AddParam("source", "tboda-widgalytics-0.1");
client.AddParam("Email", _username);
client.AddParam("Passwd", _password);
client.AddParam("service", "analytics");
client.AddHeader("GData-Version", "2");
try {
client.Execute(RequestMethod.POST);
} catch (Exception e) {
e.printStackTrace();
}
String response = client.getResponse();
解析响应后,如果要进行另一个Web Service调用,只需使用不同的URL和Parameters创建另一个RestClient对象并调用execute方法,如下所示,
RestClient client1 = new RestClient(GET_INFO_URL);
client1.AddParam("userid", "123");
try {
client1.Execute(RequestMethod.POST);
} catch (Exception e) {
e.printStackTrace();
}
String response1 = client1.getResponse();
答案 1 :(得分:0)
最后我解决了我的问题,在我的团队负责人的指导下面是我们在constants.java类中使用的代码
public static final String GET_CENTRAL_SERVER = String.format("%s/AccountService/security/ValidateAccess", TIMEMACHINE_ACCOUNTS_SERVER);
并在serversync.java类中添加代码段
public String getCentralServer(Context context, String serial_number) throws Exception{
// TODO Auto-generated method stub
WebServiceClient client = new WebServiceClient(Constants.GET_CENTRAL_SERVER);
client.addParam("accesscode", String.valueOf(serial_number));
client.addParam("type", "2");
client.Execute(RequestMethod.GET);
String response = client.getResponse();
if (response != null){
response = response.replaceAll("\\\\/", "/");
response = response.replace("\"", "");
response = response.replace("\n","");
response = "http://" + response;
return response;
}
return null;
}