0
votes
public class Http_Read_PLC_Value {
public static void main(String args[]){
    String nextLine;
    URL url = null;
    URLConnection urlConn = nullone
    InputStreamReader  inStream = null;
    BufferedReader buff = null;
    try{
        url = new URL("http://api.enda.com/devive/mac_address/password/read/MW/0");
        urlConn = url.openConnection();
        inStream = new InputStreamReader( urlConn.getInputStream());
        buff= new BufferedReader(inStream);
        while (true){
            nextLine =buff.readLine();  
            if (nextLine !=null){
               System.out.println(nextLine);      
            }
            else break;
        }
    }
    catch(MalformedURLException e) { System.out.println("Check URL :" + e.toString() ); }
    catch(IOException  e1) { System.out.println("Can't read : "+ e1.toString() ); }
  }
}

OUTPUT of Console : {"Result":[1572],"Status":"OK"}

My Question :

The value of bracked is changing between 0 & 28800 and boolean. That value sometimes one character (like[2]), sometimes five character (like[27924]), sometime [true] or [false].When I run that prg, I need a string value of bracked. How I can get ?

1

1 Answers

0
votes
 while (true){
        nextLine =buff.readLine();  
        if (nextLine !=null){
           System.out.println(nextLine);      
        }
        else break;

        // I added that line and solved my problem
        System.out.println(nextLine.substring((Integer.valueOf(nextLine.indexOf('[')) + 1),(Integer.valueOf(nextLine.indexOf(']')))));

    }
}
catch(MalformedURLException e) { System.out.println("Check URL :" + e.toString() ); }

OUTPUT of Console : {"Result":[18627],"Status":"OK"} 18627

Thanks for your interest