How to get json data from url in android studio

This article about get JSON data from URL in an android example, In this article, we will going to learn how to get JSON data from URL.

In this project we will first create php script for convert data to json format.

What you can learn in this Android Tutorial?

  • In this tutorial, You can learn how to create a PHP script for JSON data.
  • Using JSON data in the android application.
  • Convert MySQL data to JSON.
  • how to we retrieve data from the database using JSON?.
  • how to fetch data from the database using JSON in PHP?.
  • get JSON from URL android studio.

Write php script for Json data

  • In this PHP script, we will create a method convert MySQL data into JSON format.
  • you can see below the PHP code.

<?php
$con=mysqli_connect(“localhost”,”id6424970_hirenpithwa”,”hiren6024",”id6424970_hiren”);

$sql=”SELECT * FROM `infodata`”;
$result=mysqli_query($con,$sql);

$data=array();
while($row=mysqli_fetch_assoc($result)){
$data[]=$row;

}

header(‘Content-Type:Application/json’);

echo json_encode($data);


?>

Now You can see bellow result after runing this php script.

[
{“id”:”1",
“name”:”Hiren Pithwa”,
“founder”:”Unique Andro Code”,
“city”:”Rajkot”,
“company_logo”:”https:\/\/uniqueandrocode.000webhostapp.com\/hiren\/info\/infoimages\/uniqueandrocode.png”,
“website”:”www.uniqueandrocode.com"
},

{“id”:”2",
“name”:”Ravi Kiyada”,
“founder”:”Sqmtrs”,
“city”:”Bombay”,
“company_logo”:”https:\/\/uniqueandrocode.000webhostapp.com\/hiren\/info\/infoimages\/sqmtrs.png”,
“website”:”www.sqmtrs.com"
},
{“id”:”3",
“name”:”Nikhil Jivrajani”,
“founder”:”Jnj Store”,
“city”:”Rajkot”,
“company_logo”:”https:\/\/uniqueandrocode.000webhostapp.com\/hiren\/info\/infoimages\/jnjstore.png”,
“website”:”www.jnjstore.in"
}
]

If you want this json data display in android app you can read This article

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store