Tuesday, 15 July 2014

java - Json object is not returned from XAMPP server -



java - Json object is not returned from XAMPP server -

i got andoird application, want result returned android textview. test on browser , yes result showed homecoming nil android application.

following code php file.

<?php $accounts = mysql_connect("localhost","user123","1234") or die (mysql_error()); mysql_select_db("user123",$accounts); if(isset($_get["id"])){ $id = $_get['id']; $result = mysql_query("select * table123 id = $id"); if($result != null){ $result = mysql_fetch_array($result); $user = array(); $user["username"] = $result["username"]; $user["password"] = $result["password"]; echo json_encode($user); }else{ } }else{ $user["username"] = "not found"; $user["password"] = null; echo json_encode($user); } ?>

following code browser result

{"username":"not found","password":null}

even result not found, should homecoming $user show me "not found". it's impossible nil returned stream. have test on browser , yes returned $user me. wrong code?

replace "localhost" "10.0.2.2"

and add together line manifest:

<uses-permission android:name="android.permission.internet" />

if utilize android 3.0 or higher (in case do). alter emulator 2.3.3 if possible, seek run code again. or add together these lines code:

strictmode.threadpolicy policy = new strictmode.threadpolicy.builder().permitall().build(); strictmode.setthreadpolicy(policy);

java php android json parsing

No comments:

Post a Comment