android php mysql json 查询_使用json从PHP-MySql服务器到Android获取图像
我正在開發一個從php服務器下載圖像并在圖像視圖中顯示圖像的應用程序.但是當我從php頁面接收圖像時
if (!empty($result)) {
if (mysql_num_rows($result) > 0) {
$result = mysql_fetch_array($result);
$user = array();
$user["image"] = base64_encode($result["image"]);
$response["success"] = 1;
$response["image_table"] = array();
array_push($response["image_table"], $user);
echo json_encode($response);
} else {
$response["success"] = 0;
$response["message"] = "No Image found";
echo json_encode($response);
}
它給了我這樣的json響應
03-30 04:43:44.013: D/Image:(2770): {"success":1,"image_table": [{"image":"\/9j\/4VeRRXhpZgAASUkqAAgAAAAMAAABBAABAAAA..........
03-30 04:43:44.253: D/skia(2770): --- decoder->decode returned false
我正在像這樣將圖像字符串解碼為位圖….
json= jsonParser.makeHttpRequest(url_img_address, "GET", params);
Log.d("Image: ", json.toString());
try {
int success = json.getInt(TAG_SUCCESS);
if (success == 1) {
address = json.getJSONArray(TAG_IMAGE_TABLE);
for (int i = 0; i < address.length(); i++) {
JSONObject c = address.getJSONObject(i);
image = c.getString(TAG_IMAGE);
byte[] dwimage = Base64.decode(image.getBytes());
System.out.println(dwimage);
bmp = BitmapFactory.decodeByteArray(dwimage, 0, dwimage.length);
}
} else {
}
} catch (JSONException | IOException e) {
e.printStackTrace();
}
我正在使用這個bm來onotherclass,將bmp設置為imageview
ivProperty.setImageBitmap(bmp);
但是它什么也沒顯示……我的異步任務活動尚未完成并且正在繼續運行…
我的問題是如何將bmp顯示到imageview以及為什么我的asyncktask未完成…….. thx提前….
總結
以上是生活随笔為你收集整理的android php mysql json 查询_使用json从PHP-MySql服务器到Android获取图像的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 内存升级攻略:2133 vs 1600,
- 下一篇: linux mysql temp 设置_