I have a database hosted on server whose field values have to be passed to my app. I would like to do with PHP. But people suggest me to use JSON too. Is JSON required? Please guide me how to pass the field values to android app.
-
1you encode your data in JSON using PHP. there are thousands of tutorials out there and thousands of answers here.Kostas Drak– Kostas Drak2016-03-22 08:50:45 +00:00Commented Mar 22, 2016 at 8:50
-
Possible duplicate of How to parse JSON in AndroidKostas Drak– Kostas Drak2016-03-22 08:55:40 +00:00Commented Mar 22, 2016 at 8:55
3 Answers
JSON means JavaScript Object Notation and it's just a way of formatting your output in a standard way.
So, if you'd like to pass data from a database to an application, you'd need to implement a small API. This can be done using PHP. At this point, you can access data from your database using a browser and parametrizing your queries using url parameters.
PHP can render the data in a simple HTML table for example, but this is just a way of presenting your data. You can also use JSON.
This means that if you need the badges a user has earned, you'll use something like this:
<link_to_your_api>/index.php?method=getBadges&user=<user>
This in turn, will make a request to the database
<?php
// 1. connect to database
// 2. query for the information
// 3. get the result as array
$result = $db->getData();
echo json_encode($result);
?>
This is just an example, hope it helps.
link to json documentation: http://www.json.org/