1:php地址http://127.0.0.6/?c=json
2:Java輸出的結果是
[{“ id”:1,“ name”:“ zhdc”},{“ id”:2,“ name”:“/u5c0f/u6731”}] index.php
<? if($ c ==“ json”){$ arr = array(array(“ id” => 1,“ name” =>“ zhdc”),array(“ id” => 2,“ name” =>“小朱”)); die(json_encode($ arr)); }}} main。公共類main {public static void main(string [] args){try {url url = new url(“ http://127.0.0.6/?c = json”); httpurlconnection httpurlConnection =(httpurlConnection)url.openconnection(); httpurlConnection.setDoInput(true); httpurlconnection.connect(); InputStream InputStream = httpurlConnection.getInputStream(); BufferedInputStream BufferedInputStream = new BufferedInputStream(InputStream);讀取器= new InputStreamReader(BufferedInputStream);字符串json =“”; int c; while((c = reader.read())!= -1){json +=(char)c; } system.out.println(json); } catch(MalformedUrlexception e){// todo自動生成的捕獲塊e.printstacktrace(); } catch(ioException e){// todo自動生成的捕獲塊e.printstacktrace(); }}}}