使用Ion从数据库中检索数据

时间:2016-04-29 14:24:56

标签: php android mysql ion

我有一个MySQL数据库,我正在为我的应用程序存储数据。现在,我想通过PHP在行

中使用Ion检索此数据
  

JSONObject jObject = new JSONObject( result );

它给我一个错误的结果

错误

Error:(207, 17) error: method setCallback in interface Future<T> cannot be applied to given types;
required: FutureCallback<JsonObject>
found: <anonymous FutureCallback<JsonArray>>
reason: actual argument <anonymous FutureCallback<JsonArray>> cannot be converted to FutureCallback<JsonObject> by method invocation conversion
where T is a type-variable:
T extends Object declared in interface Future

MainActivity.java

      boolean loading=Ion.with(getApplicationContext()).load(URLPHP)
            .asJsonObject()
            .setCallback(new FutureCallback<JsonArray>() {
                public void onCompleted(Exception e,JsonArray result) {

                    try {
                        JSONObject jObject = new JSONObject(result);
                        JSONArray jArray = jObject.getJSONArray("Items");

                        for (int i = 0; i < jArray.length(); i++) {
                            JSONObject jObject_0 = jArray.getJSONObject(i);
                            JSONObject Info = jObject_0.getJSONObject("item_info");
                            JSONObject costs = jObject_0.getJSONObject("item_cost");
                            Log.e("Item", Info + ", " + costs);
                        }

                    } catch (JSONException xe) {
                        // TODO Auto-generated catch block
                        xe.printStackTrace();
                    }
                }
            });

PHP

<?php

if($_SERVER["REQUEST_METHOD"]=="POST"){
    include 'connection.php';
    showItem();
}

function showItem()
{
    global $connect;

    $query = " Select * FROM Items; ";

    $result = mysqli_query($connect, $query);
    $number_of_rows = mysqli_num_rows($result);

    $temp_array  = array();

    if($number_of_rows > 0) {
        while ($row = mysqli_fetch_assoc($result)) {
            $temp_array[] = $row;
            echo '$row';
        }
    }
    echo "Fertig";

    header('Content-Type: application/json');
    echo json_encode(array("Items"=>$temp_array));
    mysqli_close($connect);

}
?>

0 个答案:

没有答案