Fix json null string

pull/26/head
Koitharu 6 years ago
parent 5af32898f8
commit 34acf5bb55

@ -7,6 +7,7 @@ import org.koitharu.kotatsu.core.model.Manga
import org.koitharu.kotatsu.core.model.MangaChapter import org.koitharu.kotatsu.core.model.MangaChapter
import org.koitharu.kotatsu.core.model.MangaSource import org.koitharu.kotatsu.core.model.MangaSource
import org.koitharu.kotatsu.core.model.MangaTag import org.koitharu.kotatsu.core.model.MangaTag
import org.koitharu.kotatsu.utils.ext.getStringOrNull
import org.koitharu.kotatsu.utils.ext.map import org.koitharu.kotatsu.utils.ext.map
import org.koitharu.kotatsu.utils.ext.safe import org.koitharu.kotatsu.utils.ext.safe
@ -44,12 +45,12 @@ class MangaIndex(source: String?) {
Manga( Manga(
id = json.getLong("id"), id = json.getLong("id"),
title = json.getString("title"), title = json.getString("title"),
altTitle = json.getString("title_alt"), altTitle = json.getStringOrNull("title_alt"),
url = json.getString("url"), url = json.getString("url"),
source = source, source = source,
rating = json.getDouble("rating").toFloat(), rating = json.getDouble("rating").toFloat(),
coverUrl = json.getString("cover"), coverUrl = json.getString("cover"),
description = json.getString("description"), description = json.getStringOrNull("description"),
tags = json.getJSONArray("tags").map { x -> tags = json.getJSONArray("tags").map { x ->
MangaTag( MangaTag(
title = x.getString("title"), title = x.getString("title"),

@ -22,3 +22,5 @@ fun <T> JSONArray.mapIndexed(block: (Int, JSONObject) -> T): List<T> {
} }
return result return result
} }
fun JSONObject.getStringOrNull(name: String): String? = opt(name)?.toString()
Loading…
Cancel
Save