要从json数组中显示只有一个图片,你可以按照以下步骤进行解决:
{
  "images": [
    "https://example.com/image.jpg"
  ]
}
Image的数据模型类,用于存储图片URL:public class Image {
    private String url;
    public Image(String url) {
        this.url = url;
    }
    public String getUrl() {
        return url;
    }
}
implementation 'com.google.code.gson:gson:2.8.7'
import com.google.gson.Gson;
// 解析json
String json = "{\"images\":[\"https://example.com/image.jpg\"]}";
Gson gson = new Gson();
Image[] images = gson.fromJson(json, Image[].class);
// 显示图片
ImageView imageView = findViewById(R.id.imageView);
Glide.with(this).load(images[0].getUrl()).into(imageView);
这里使用了Glide库来加载和显示图片。确保你已经在build.gradle文件中添加了Glide库的依赖:
implementation 'com.github.bumptech.glide:glide:4.12.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.12.0'
当你运行应用程序时,它将从json中解析出图片URL,并使用Glide库将图片显示在ImageView中。请确保你已经将ImageView添加到你的布局文件中。