I'm doing some research on开发者_开发百科 how to pull information from a MySQL DB to display information in an application but I'm wondering what would be a good way to do this? Right now I'm thinking something like...
ANDROID APP <--> HTTP (display XML to pull and display on app) <--> DB Server.
I read about JSON and some other ways to do this, but I just was wondering if anyone knows the best way to do this.
Yes i would use php to connect and output it as json which is easily parseable by android
You can use this http://php.net/manual/en/function.json-encode.php
$query = mysql_query("SELECT ...");
$rows = array();
while($row = mysql_fetch_assoc($query)) {
$rows[] = $row;
}
echo json_encode($rows);
At a high level, yes, that's how you would do it. JSON is easy to handle on the Android side, so it may be a good choice for you. There are nuances to doing this type of access well on the Android platform that you should be aware of. There is a video on the Android Developer's site that covers design patterns for accessing REST services from Android. Look for Android REST client applications in the video list.
精彩评论