java—从url加载json文件名并附加到另一个url以获取图像

ar5n3qh5  于 2021-07-06  发布在  Java
关注(0)|答案(0)|浏览(188)

我是java新手,我正在尝试加载一个json url来获取文件名列表,并将每个文件名附加到另一个url来获取每个图像。jsonurl中的内容示例如下所示。
json url=“https://example.com/index.json“{”name“:”foo“,”pictureset“:[”image1“,”image2“,”image3“,”image4“,”image5“],”tile“:”tile\u image1“}
第二个url=“https://example.com/index/images. 为了获得实际的图像,我想将pictureset中的每个字符串附加到第二个url和add.png。例如https://example.com/index/images/image1.png“为了得到真实的图像。

public LiveData<ArrayList<Puzzle>> loadItemFromJason()
    {
        RequestQueue queue = Volley.newRequestQueue(mApplicationContext);
        String url = "https://example.com/index.json";
        final MutableLiveData<ArrayList<Puzzle>> mutableItems = new MutableLiveData<>();
        JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(
                Request.Method.GET, url, null,
                new Response.Listener<JSONObject>(){
                    @Override
                    public void onResponse(JSONObject response) {

                        ArrayList<Puzzle> items = parseJSONResponse(response);
                        mutableItems.setValue(items);
                        mPuzzle = mutableItems;
                    }
                },

                new Response.ErrorListener()
                {
                    @Override
                    public void onErrorResponse(VolleyError error) {
                        String errorResponse = "That didn't work";
                    }
                });

        queue.add(jsonObjectRequest);
        return mutableItems;
    }
  private ArrayList<Item> parseJSONResponse(JSONObject pResponse)
    {
      // ArrayList<JSONObject> mObjects = new ArrayList();
      // ArrayList<Bitmap> mImages = new ArrayList();
        ArrayList<Item> items = new ArrayList();

        try{
            JSONArray itemArray = pResponse.getJSONArray("PictureSet");
            for(int i = 0; i < itemArray.length(); i++)
            {
                JSONObject itemObject = itemArray.getJSONObject(i);
                Item item = appendItems(itemObject);
                items.add(item);
            }
        }
        catch(JSONException e){
            e.printStackTrace();

        }
        return  items;
    }

 private Item appendItems(JSONObject pItemobject) throws org.json.JSONException{

       //I will like to append each pItemobject to 
           https://example.com/index/images
        return item;
    }

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题