double820122 2014-04-16 16:25
浏览 41
已采纳

将URL添加到图像名称

I am retrieving JSON objects from a PHP file to my Android app. One of the objects attributes is an image file name. All images are hosted on a web folder.

At this moment, the object attribute is the image file name, but I need the complete URL to the file to be able to display the image on the app.

What should I do to obtain a better performance:

  1. Add the URL string to the file name at the PHP file prior to execute the JSONencode function?
  2. Add the URL string to the file name at the app code after receiving the JSON array from the web server?

This is the piece of code I am using to retrieve the JSON array:

protected Void doInBackground(Void... params) {
            // Create an array
            arraylist = new ArrayList<HashMap<String, String>>();
            // Retrieve JSON Objects from the given URL address
            jsonobject = JSONfunctions
                    .getJSONfromURL("http://.../android_ofertaslist_todas.php");

            try {
                // Locate the array name in JSON
                jsonarray = jsonobject.getJSONArray("Categorias");

                for (int i = 0; i < jsonarray.length(); i++) {
                    HashMap<String, String> map = new HashMap<String, String>();
                    jsonobject = jsonarray.getJSONObject(i);
                    // Retrive JSON Objects
                    map.put("valoracionEmpresa", jsonobject.getString("valoracionEmpresa"));
                    map.put("nombreEmpresa", jsonobject.getString("nombreEmpresa"));
                    map.put("direccionEmpresa", jsonobject.getString("direccionEmpresa"));
                    map.put("strImagen", jsonobject.getString("strImagen"));//<--- THIS IS THE IMAGE FILE NAME
                    // Set the JSON Objects into the array
                    arraylist.add(map);
                }
            } catch (JSONException e) {
                Log.e("Error", e.getMessage());
                e.printStackTrace();
            }
            return null;
        }
  • 写回答

1条回答 默认 最新

  • dongxiang5879 2014-04-16 16:35
    关注

    both ways will result same performance:

    1. Add the URL string to the file name at the PHP file prior to execute the JSONencode function?
    2. Add the URL string to the file name at the app code after receiving the JSON array from the web server?

    better way is add url string at server side and retrieve absolute path of image in json, so that in future you can change the location of your images and url on server without doing any change at your mobile app code.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效