diff --git a/docs/converter-struct.md b/docs/converter-struct.md index 8a3a7c041..775a0a123 100644 --- a/docs/converter-struct.md +++ b/docs/converter-struct.md @@ -85,17 +85,51 @@ scopeNetLife { } ``` -## JSON数组 +## 不规范数据 -在Net中解析List/Map等和普通对象没有区别, 取决于如何实现转换器 +推荐在转换器中解析之前处理好数据 + +1. 字段值为`"null"`而不是`null`, 或者json在字符串中 + ```json + { + "data": "{ "title": "name" }" + "msg": "null" + } + ``` + ```kotlin title="替换为规范内容" + json = bodyString.replace("\"{", "{") + json = bodyString.replace("}\"", "}") + json = bodyString.replace("\"null\"", "null") + ``` + +2. 服务器成功时不返回数据或者返回`null` + ```kotlin + if (response.body == null || bodyString == "null") { + "{}".bodyString.parseBody(succeed) + } + ``` + +3. 字段值为null, 使用 [kotlin-serialization](kotlin-serialization.md) 自动使用字段默认值 + ```kotlin + { + "msg": null + } + ``` +4. 字段无引号或字段名为数字, 使用 [kotlin-serialization](kotlin-serialization.md) 可以禁用JSON规范限制 + ```json title="数字使用map解析" + { + "data": { + 23: 32 + } + } + ``` + ```kotlin hl_lines="3" title="禁用JSON规范限制" + val jsonDecoder = Json { + // ... + isLenient = true + } + ``` -```kotlin -scopeNetLife { - tvFragment.text = Get>("list") { - converter = GsonConverter() // 单例转换器, 一般情况下是定义一个全局转换器 - }.await()[0].name -} -``` ## 泛型数据类 diff --git a/docs/css/extra.css b/docs/css/extra.css index 3f5119d0a..a3ccf56a6 100644 --- a/docs/css/extra.css +++ b/docs/css/extra.css @@ -46,6 +46,8 @@ code, font-size: 14px !important; } -.md-typeset .admonition-title, .md-typeset summary { +.highlight span.filename, +.md-typeset .admonition-title, +.md-typeset summary { font-weight: normal; } \ No newline at end of file diff --git a/mkdocs.yml b/mkdocs.yml index bf153d2ea..40f00d2f8 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -1,11 +1,6 @@ site_name: Net site_description: Net document repo_url: https://github.com/liangjingkanji/Net - -site_author: 劉強東 -copyright: Copyright © 2018 - 2020 劉強東 -repo_name: GitHub -docs_dir: 'docs' extra: social: - icon: fontawesome/brands/github @@ -14,6 +9,11 @@ extra: link: https://raw.githubusercontent.com/liangjingkanji/liangjingkanji/master/img/group-qrcode.png - icon: fontawesome/brands/twitch link: https://github.com/liangjingkanji/Net/discussions + +site_author: 劉強東 +copyright: Copyright © 2018 - 2023 劉強東 +repo_name: GitHub +docs_dir: 'docs' extra_css: - css/extra.css theme: