Android communicating with web server data - android

I am writing a android application to read a php script in my LAMP server which display the data inside mysql database. The php script simply fetches all rows inside my database table.
I would like to ask if there is any method to parse the information of the php script and set the textview inside the application with the information fetched.
Should my php script echo the data in text, array or JSON format?
What methods or direction should I follow to fetch and parse the data into my android application?
Thanks

I think that JSON is the best format to use, as there are good JSON libraries around .
If you use a JSON library such as Gson or Jackson you can have the library map the JSON recieved from your php script to a Java domain class. So the library will parse the JSON and create an instance of your Java class for you.
Then it is easy to fill your textview with the values from your java object.

The above answer gives the details about what you may do in your app to parse the JSON data . I would like to add more details regarding how you can create the JSON object inside your php files . You may use the json_encode php function to convert the data that you get from your database into a JSON format .
PHP json_encode official documentation with exampes

Related

fetch json data from url and update

I'm new here, give me a solution about json please.
I want to fetch json data to my app from url, and also want to update json data regularly without url change.
suppose, i want to show trending products in an activity, after one day i will change some products of that activity by changing data from json. after updating my json, url cant be change, cause doing update whole app regularly for changing url is not a good idea.
so, is this possible to update json data without changing url?
if yes, tell me please where can i store my json so that i can update t regularly.
or if you can provide any other better possible way to do this, please help me.
Thank you.
That's why we use the database
Basically you need a database o structure your data, then you fetch data from the database using PHP which gives you a Json response
Since you are using Android Studio tag here is a good tutorial on how to fetch data from database using PHP , Json response tutorial
First you gonna start with LocalHost , consider using Xampp , Then use web hosting
You create your database using PhpMyAdmin in LocalHost/phpMyAdmin and you read the data using PHP which return it in Json Format
Then migrate to Web Hosting , in PhpMyAdmin you can export your Database from your LocalHost and Import it in your WebHost/PhpMyAdmin , and you upload your Php files also

How to create POJO if I don't have a json?

I want to parse website using retrofit, but I don't know how to create POJO.
And I don't have a json.
http://vuzopedia.ru/vuz/
This is the website where I want to parse information.
if your website does not have an API or anyway to get JSON data then you should consider Web Scraping. You cant make POJO/Models without JSON Data

Android application which can parse json recieved from server into meaningful datasets

I want to develop an android application which parses json data into some meaningful data sets and accordingly display them into the UI .
I need suggestions on how to go about it.
PS : i have 0 idea of the available options to chose , so different ways to do the same would help me a lot , since i am new to it
Thanks in advance
You can use gson for parsing the data together with some network library like volley or can use retrofit which provide direct parsing with the help of gson and other lib.
To accomplish this you first need to create some relevant Java pojo
For corresponding json dataset , so that you can use it .
You can generate pojo from this website very easily for any json data
http://www.jsonschema2pojo.org/

Convert json into mysql database?

Can we convert json format data coming from server into mysql database or means can we store
the data coming through json into mysql database.
Thanks .
Although not a 'yes' in the sense that you can just shove a JSON string at MySQL and have it insert the data itself, yes, you can programmatically take a JSON string, parse it, and insert that data into a MySQL database. You may want to look at something like JSON-to-MySQL, which is a set of PHP scripts that can take arbitrary JSON data and convert it to SQL data.
The most common way is parser you Json data to Object and store it in database.
I recommend you use Jackson, see here and here a simple example.
Hope its help

Get Json Information? (Noob)

I'm new to both using json and developing for android, however I'm looking to learn how to retrieve information using a json api key.
Let's say this website has all the information I need. How can I access and store that information?
https://website.com/api/user/key/a015b92aec875bd24e8fdc73477bfdcr
For example it would have something like this,
{"balance":"123","due":"3426"}
To access it, you need to open HTTPS connection to the server that has that API key, which is that https address you just provided. The server will return the JSON objects for you, to parse the string data, you can use GSON. GSON will translate all the JSON objects into Java objects, and it will help you populate your pre-built Java data structures with those data
You can get the web content using the Android HTTPClient (or follow something like the guide on this page).
For storage, you need to parse the JSON - see this SO question.
For storage, either store the raw JSON in a file or create an SQLite database and store it according to your specifications.

Categories

Resources