原因在于lottie 源码中的这一段。如果 contentType 不满足判断为zip 的条件。会导致他被当做json处理。解析失败
@NonNull
private LottieResult<LottieComposition> fromInputStream(Context context, @NonNull String url, @NonNull InputStream inputStream, @Nullable String contentType,
@Nullable String cacheKey) throws IOException {
FileExtension extension;
LottieResult<LottieComposition> result;
if (contentType == null) {
// Assume JSON for best effort parsing. If it fails, it will just deliver the parse exception
// in the result which is more useful than failing here.
contentType = "application/json";
}
if (contentType.contains("application/zip") ||
contentType.contains("application/x-zip") ||
contentType.contains("application/x-zip-compressed") ||
url.split("\\?")[0].endsWith(".lottie")) {
Logger.debug("Handling zip response.");
extension = FileExtension.ZIP;
result = fromZipStream(context, url, inputStream, cacheKey);
} else {
Logger.debug("Received json response.");
extension = FileExtension.JSON;
result = fromJsonStream(url, inputStream, cacheKey);
}
if (cacheKey != null && result.getValue() != null && networkCache != null) {
networkCache.renameTempFile(url, extension);
}
return result;
}
网友评论