douzhantanju1849 2015-10-29 00:37
浏览 69

Android图像GridView + MySql

I have some images in my db. I´m trying to populate a gridview but nothing is loaded. This is the logcat:

org.json.JSONException: Value http://fisioterapeutacamila.com/iMoveis/img/apto01.jpg at images of type java.lang.String cannot be converted to JSONArray
10-28 20:29:41.055 1679-1695/? W/System.err:     at org.json.JSON.typeMismatch(JSON.java:100)
10-28 20:29:41.059 1679-1695/? W/System.err:     at org.json.JSONObject.getJSONArray(JSONObject.java:553)
10-28 20:29:41.063 1679-1695/? W/System.err:     at com.javatechig.gridviewexample.GridViewActivity.parseResult(GridViewActivity.java:160)

This is my json parser

private void parseResult(String result) {
    try {
        JSONObject response = new JSONObject(result);
        JSONArray posts = response.optJSONArray("posts");
        GridItem item;
        for (int i = 0; i < posts.length(); i++) {
            JSONObject post = posts.optJSONObject(i);
            //String title = post.optString("title");
            item = new GridItem();
            //item.setTitle(title);
            JSONArray attachments = post.getJSONArray("images");
            if (null != attachments && attachments.length() > 0) {
                JSONObject attachment = attachments.getJSONObject(0);
                if (attachment != null)
                    item.setImage(attachment.getString("url"));
            }
            mGridData.add(item);
        }
    } catch (JSONException e) {
        e.printStackTrace();
    }
}

Php file

<?php

  include_once 'db_connect.php';

  $sql = "SELECT * FROM iMoveis";
  $result = mysqli_query($mysqli, $sql);

  $v = '{"posts":[';

  while($row = mysqli_fetch_array($result)){

   $v .= '{"images":"'.$row['img1'].'", "images":"'.$row['img2'].'", "images":"'.$row['img3'].'", 
"images":"'.$row['img4'].'", "images":"'.$row['img5'].'"},';

 }

  $v .= ']}';
  echo $v;

?>

What is wrong here? PHP or the parser on java class? I have changed my parseResult but still got nothing loaded on gridview. Could anyone help me with php json format? Thanks in advance.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
    • ¥15 微信会员卡接入微信支付商户号收款
    • ¥15 如何获取烟草零售终端数据
    • ¥15 数学建模招标中位数问题
    • ¥15 phython路径名过长报错 不知道什么问题
    • ¥15 深度学习中模型转换该怎么实现
    • ¥15 HLs设计手写数字识别程序编译通不过
    • ¥15 Stata外部命令安装问题求帮助!
    • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
    • ¥15 TYPCE母转母,插入认方向