Skip to content

Commit

Permalink
doc: 更新开发文档
Browse files Browse the repository at this point in the history
  • Loading branch information
liangjingkanji committed Aug 11, 2023
1 parent be02131 commit 19ec17b
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 15 deletions.
52 changes: 43 additions & 9 deletions docs/converter-struct.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<R>(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<UserModel>>("list") {
converter = GsonConverter() // 单例转换器, 一般情况下是定义一个全局转换器
}.await()[0].name
}
```

## 泛型数据类

Expand Down
4 changes: 3 additions & 1 deletion docs/css/extra.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
10 changes: 5 additions & 5 deletions mkdocs.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
site_name: Net
site_description: Net document
repo_url: https://github.com/liangjingkanji/Net

site_author: 劉強東
copyright: Copyright &copy; 2018 - 2020 劉強東
repo_name: GitHub
docs_dir: 'docs'
extra:
social:
- icon: fontawesome/brands/github
Expand All @@ -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 &copy; 2018 - 2023 劉強東
repo_name: GitHub
docs_dir: 'docs'
extra_css:
- css/extra.css
theme:
Expand Down

0 comments on commit 19ec17b

Please sign in to comment.