简体   繁体   English

如何解析来自Web服务URL的json响应并将其解析为android中的url

[英]how to parse json response from webservice url and parse it as url in android

I have an application in that i called webservice using this link ,I have one webservice Url and another Url is getting as response from that url.I need to use that url as 我有一个应用程序,我使用此链接调用了webservice,我有一个webservice Url,另一个URL从该URL获得响应。我需要将该URL用作

public static final String TIME_CENTRAL_SERVER = " http://accounts.myexample.com/Services "; public static final String TIME_CENTRAL_SERVER =“ http://accounts.myexample.com/Services ”; in the place of " http://accounts.myexample.com/Services " i need to parse my json response. 在“ http://accounts.myexample.com/Services ”的地方,我需要解析我的json响应。

I have check for that in google but couldn't get any answer can anyone help me regarding this, Thanks in advance. 我已经在Google中进行了检查,但无法得到任何答案,任何人都可以就此进行帮助,谢谢。 If anyone have queries ask me. 如果有人有疑问请问我。

First webservice call is like below 第一次网络服务呼叫如下

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();

After parsing the response, if you want to do another Web Service call, just create another object of RestClient with different URL and Parameters and call execute method, like below, 解析响应后,如果要执行另一个Web Service调用,只需创建另一个具有不同URL和参数的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();

finally i solved my issue with guidance of my team head below is the code which we have used in constants.java class 最终我在团队负责人的指导下解决了我的问题,下面是我们在constants.java类中使用的代码

public static final String GET_CENTRAL_SERVER = String.format("%s/AccountService/security/ValidateAccess", TIMEMACHINE_ACCOUNTS_SERVER);

and add code snippet in serversync.java class 并在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;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM