简体   繁体   中英

Can I get a data from PHP server to Android application with JSON?

I am not sure about understanding about JSON, PHP, and MySQL.

In my plan, I will create a web server and android application.The database server is MySQL. In my understanding, PHP can send data and encode it into a JSON array, how can I use this JSON array in my Android application?

following is PHP code...

<?php
mysql_connect("host","username","password");
mysql_select_db("Deal");
$sql=mysql_query("select * from CITY where CITY_NAME like 'A%'");
while($row=mysql_fetch_assoc($sql))
$output[]=$row;
print(json_encode($output));
mysql_close();
?>

here is a nice article link . i hope you like it, and if you have any question, you can ask, i will try to solve it as soon as possible.

Your question is difficult to understand.

It seems like you're asking how to send JSON data using PHP.

Use the PHP json_encode and json_decode functions to convert between JSON and PHP arrays.

To send a JSON string, first convert the array to JSON using json_encode() , then print the resulting string and exit the program.

<?php
$my_array = array('this'=>'is', 'just'=>'an', 'example'=>'array');

$json_string = json_encode($my_array);
print $json_string;
die;
?>

Hope that helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM