PHP code ============================ $array = Array (' username ' => ' Yang Ji ', ' Password ' => ' 123456 ', ' user_id ' =>1);
echo Json_encode ($array);
Java Code ============================
private void Starturlcheck (String username,string password) {httpclient client = new Defaulthttpclient (); StringBuilder builder = new StringBuilder (); HttpGet myget = new HttpGet ("http://10.0.2.2/Android/index.php"); try {httpresponse response = Client.execute (Myget); BufferedReader reader = new BufferedReader (New InputStreamReader (Response.getentity (). GetContent ())); for (String s = reader.readline (); s!= null; s = Reader.readline ()) {builder.append (s);} Jsonobject jsonobject = new Jsonobject (builder.tostring ()); String re_username = jsonobject.getstring ("username"); String Re_password = jsonobject.getstring ("password"); int re_user_id = Jsonobject.getint ("user_id"); Settitle ("User id_" +re_user_id); LOG.V ("url response", "true=" +re_username); LOG.V ("url response", "true=" +re_password); catch (Exception e) {log.v ("url response", "false"); E.printstacktrace ();} Run results =================================== where http://10.0.2.2 is the IP address of the native URL for Android access. http://127.0.0.1 for testing on the computer throws an exception when executing code php100.com Java.net.SocketException:Permission denied This has insufficient permissions to access the network for Applications In Androidmanifest.xml, the following configuration is required: <uses-permission android:name= "Android.permission.INTERNET"/> is added to the </ Manifest> before the test is done.