2

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.

2
  • 1
    you encode your data in JSON using PHP. there are thousands of tutorials out there and thousands of answers here. Commented Mar 22, 2016 at 8:50
  • Possible duplicate of How to parse JSON in Android Commented Mar 22, 2016 at 8:55

3 Answers 3

1

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/

Sign up to request clarification or add additional context in comments.

Comments

1

You pass the data to your app, when it makes a request to your PHP script. JSON is handy because you can package your data in a format, that is both well readable by humans and machines. You can use the gson library then, to process the JSON data in your app.

Comments

0

Create REST api using any server side script PHP,nodejs or any you like which returns JSON response

call the rest api using http request which returns JSOn text

decode the JSON string to JSON object and use with your android code

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.