【问题标题】:Read PLC from web从网上读取 PLC
【发布时间】:2014-03-25 18:11:11
【问题描述】:
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() ); }
  }
}

控制台输出:{"Result":[1572],"Status":"OK"}

我的问题:

braked 的值在 0 和 28800 和布尔值之间变化。该值有时是一个字符(如 [2]),有时是五个字符(如 [27924]),有时是 [true] 或 [false]。当我运行该 prg 时,我需要一个带括号的字符串值。我怎样才能得到?

【问题讨论】:

    标签: plc


    【解决方案1】:
     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() ); }
    

    控制台输出:{"Result":[18627],"Status":"OK"} 18627

    感谢您的关注

    【讨论】:

      猜你喜欢
      • 2016-06-13
      • 2018-01-14
      • 1970-01-01
      • 2021-12-14
      • 2018-10-23
      • 2016-02-09
      • 2017-03-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多