Android App - Retrieve Data from PHP JSON output -
yesterday figured out how encode mysql database entries php.
i want :
- make http request php script laying on computer(xampp environment).
- convert retrieved json data array of type song(i made class already).
- put entries listview.
i tried 20 solutions had found far. either dont work or whole app crashes.
what tried far:
i tried android developer site reads android studio shows errors then:
establish connection in asynctask->getting data httpurlconnection(method="post") getting data of request string->parsing string->decoding string json.
i can't write code here 'cause nothing worked @ , started on 100 times.
my php script is:
<?php error_reporting(e_all); ini_set('display_errors', 1); require_once 'config.php'; $connection = new mysqli($server,$user,$password,$database); // check connection if ($connection->connect_error) { die('connect error (' . $connection->connect_errno . ') ' . $connection->connect_error); } $songs=array(); $sql = 'select * tb_song'; $result = $connection->query($sql); while($row=$result->fetch_assoc()){ //$songs[]=$row; //$jsons['songs'][]=json_encode($row); //$songs[]=$row; array_push($songs,$row); } //print_r($songs); echo json_encode(array('songs'=>$songs)); //print_r($songs); $connection->close(); ?>
the output of scipt (shortened):
json {"songs":[{"id":"1","title":"mr highways thinking end","artist":"a day remember","album":"default","url":"192.168.0.22\/library\/a day remember - mr highways thinking end.mp3"},{"id":"2","title":"the business of living","artist":"adept","album":"another year of disaster","url":"192.168.0.22\/library\/adept\/another year of disaster\/01 business of living.mp3"}]}
i don't know error appears 'cause compiler said arraylist created empty.
i used tutorials from:
https://www.codeofaninja.com/2013/11/android-json-parsing-tutorial.html
http://www.evanjbrunner.info/posts/json-requests-with-httpurlconnection-in-android/
http://developer.android.com/reference/android/os/asynctask.html
http://developer.android.com/reference/android/util/jsonreader.html
http://developer.android.com/reference/java/net/httpurlconnection.html
but nothing helped me.
i appreciate if me. links tutorials welcome.
Comments
Post a Comment