使用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
对于给定的响应,是否可能?
发布于 2021-06-10 01:37:44
错误消息清楚地指出,您将type指定为Object (Response),但收到了String。我假设将返回类型更改为字符串应该有效
@Headers("Content-Type: image/svg+xml")
@GET("url/{id}")
suspend fun getIcon(
@Path("id") iconId: UUID
): Response<String> 或者只是
@Headers("Content-Type: image/svg+xml")
@GET("url/{id}")
suspend fun getIcon(
@Path("id") iconId: UUID
): Stringhttps://stackoverflow.com/questions/60340988
复制相似问题