StringRequest ExampleRequest = new StringRequest (Request.Method.GET, url, new Response.Listener<String>() {
StringBuilder data = new StringBuilder();
@Override
public void onResponse(String response) {
System.out.println("Request response : " + response);
try {
// converting the string to json array object
JSONArray array = new JSONArray(response);
// traversing through all the object
for (int i = 0; i < array.length(); i++) {
// getting shop object from json array
JSONObject obj = array.getJSONObject(i);
// adding the shop to shop list
int shopId = obj.getInt("shop_id");
String shopName = obj.getString("shop_name");
double shopLat = obj.getDouble("shop_lat");
double shopLng = obj.getDouble("shop_lng");
System.out.println("Id : " + shopId);
System.out.println("Nom : " + shopName);
System.out.println("Lat : " + shopLat);
System.out.println("Lng : " + shopLng);
data = insertShops(data, shopId, shopName, shopLat, shopLng);
}
try {
// saving the file into device
FileOutputStream out = openFileOutput("data.csv", Context.MODE_PRIVATE);
out.write((data.toString()).getBytes());
out.close();
printData();
updateShopsTable();
} catch(Exception e) {
e.printStackTrace();
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() { // Create an error listener to handle errors appropriately.
@Override
public void onErrorResponse(VolleyError error) {
// This code is executed if there is an error.
System.out.println("Request error : " + error);
}
});
ExampleRequestQueue.add(ExampleRequest);
Bon j'ai fais ca ca l'air moche mais ca marche
<?php
require_once "$_SERVER[DOCUMENT_ROOT]/model/ShopManager.php";
$shopManager = new ShopManager();
// Select shops
$shops = $shopManager->selectShops();
$shops_array = array();
foreach ($shops as $shop) {
$temp = array();
$temp['shop_id'] = $shop['shop_id'];
$temp['shop_name'] = $shop['shop_name'];
$temp['shop_lat'] = $shop['shop_lat'];
$temp['shop_lng'] = $shop['shop_lng'];
array_push($shops_array, $temp);
}
echo json_encode($shops_array);