convert to php encode_json to org.json.jsonobject

messages

org.json.JSONException: Value Array of type java.lang.String cannot be converted to JSONObject



solution
php side

$query = "SELECT * FROM _cash ORDER BY idx DESC LIMIT 10";
$result = mysql_query($query);
$str_json = array();
while($arrReturn = mysql_fetch_array($result)){
// /$str_json[] = json_encode($arrReturn);
$arrReturn["cash"] = number_format($arrReturn["cash"]);
$str_json[] = $arrReturn;
}
// print_r($arrReturn);
$outputArr['Android'] = $str_json;
echo (json_encode($outputArr));

android side

        JSONObject holder = getHttpJson(getApplicationContext(), "http://www.qd.com/abclogin.php?mode=pays");
//        JSONArray data = new JSONArray(holder);
        JSONArray jsonArray = holder.optJSONArray("Android");
        Log.d(TAG, "jsonArray.length(): " + String.valueOf(jsonArray.length()));
        for (int i = 0; i < jsonArray.length(); i++) {
            PaymentsListBean paymentsListBean = new PaymentsListBean();
            try {
//                Log.d(TAG, "holder: " + holder.toString(i));
                JSONObject jsonObject = jsonArray.getJSONObject(i);
                Log.d(TAG, "cash:" + jsonObject.get("cash"));
                paymentsListBean.setCash(jsonObject.getString("cash"));
                paymentsListBean.setMethod( jsonObject.getString("method"));
                paymentsListBean.setRegdate(jsonObject.getString("regdate"));
                results.add(paymentsListBean);
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }

댓글

가장 많이 본 글