Read PLC from web -
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 changing between 0 & 28800 , boolean. value 1 character (like[2]), 5 character (like[27924]), sometime [true] or [false].when run prg, need string value of bracked. how can ?
while (true){ nextline =buff.readline(); if (nextline !=null){ system.out.println(nextline); } else break; // added line , solved 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 interest
Comments
Post a Comment