【发布时间】:2020-06-06 00:30:47
【问题描述】:
使用 Retrofit + Moshi 如何将 SVG 放入 ImageView。
来自服务器的响应:
<svg xmlns="http://www.w3.org/2000/svg" width="33" height="32" viewBox="0 0 33 32" fill="none"><ellipse cx="16.3233" cy="16" rx="16.2874" ry="16" fill="#E6F5F5" /></svg>
改造:
Retrofit.Builder()
.client(okHttpClient)
.addConverterFactory(MoshiConverterFactory.create(moshi).asLenient())
@Headers("Content-Type: image/svg+xml")
@GET("url/{id}")
suspend fun getIcon(
@Path("id") iconId: UUID
): Response<whatever>
Moshi 设置:
private val moshi = Moshi
.Builder()
.add(KotlinJsonAdapterFactory())
.build()
Moshi 错误:
com.squareup.moshi.JsonDataException: Expected BEGIN_OBJECT but was STRING at path
给定的响应是否可能?
【问题讨论】:
-
添加整个异常和您要反序列化响应的模型类。
-
这是整个消息,模型是什么,可以是字符串
标签: android svg retrofit moshi