0

i have code in my android project that download json string from rest api , but the url inside downloaded string is invalid its become like : in some reason the url correct it's self in stackoverflow site but i mean the dashes become like this in log cat : (https : // www. example.com this is screenshot from log cat : url screenshot from logcat can someone help me to fix this problem , thank you in advance

this is my code that i write to retrieve json from api :

public class LoadThread extends Thread {

private PakageParams pakage = new PakageParams() ;

private void preparePakage(){
    pakage.setUri("https://example/api/v2.1/search?");
    pakage.setMethod("GET");
    pakage.setParams("lat","25.800693");
    pakage.setParams("lon", "55.976199");
}

public void run() {


    if(!isInterrupted()){

        String json = loadData();
        if(json != null ){
            EventBus.getDefault().post(new OnjsonLoaded(json));
        } else {
            EventBus.getDefault().post(new OnjsonLoaded("caanot load json"));
        }

    }


}

private String loadData(){
    preparePakage();
    String uri = pakage.getUri();
    uri += pakage.getEncodedParams();
    BufferedReader reader =  null ;
    HttpURLConnection conn = null ;
    try {
        URL url = new URL(uri);
        conn = (HttpURLConnection) url.openConnection();
        conn.setRequestMethod("GET");
        conn.setRequestProperty("Content-Type", "application/json");
        conn.setRequestProperty("user-key",API_KEY_STRING);

        reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
        StringBuilder sb = new StringBuilder();
        String line = null ;
        while((line = reader.readLine())!= null){
            sb.append(line );
        }
        return sb.toString();

    } catch (MalformedURLException e){
        return null ;
    } catch (IOException e) {
        e.printStackTrace();
        if(reader !=null ){
            try {
                reader.close();
                conn.disconnect();
            } catch (IOException e1) {
                e1.printStackTrace();
                return e1.getMessage() ;
            }
        }
        return e.getMessage() ;
    }


}

}

aboodrak
  • 873
  • 9
  • 15
  • In Log cat the URL will be printed like that , but if you will make the network call , it should work fine – Haroon May 11 '16 at 08:29
  • http://stackoverflow.com/questions/1580647/json-why-are-forward-slashes-escaped – laalto May 11 '16 at 09:27

1 Answers1

0

Don't worry it will work fine when you will call it. (Y)

Kaushal Kishor
  • 411
  • 4
  • 9