2
安卓该如何显示 slatejs 格式的数据?
source link: https://www.v2ex.com/t/796631
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
安卓该如何显示 slatejs 格式的数据?
服务器接口返回的数据是 slatejs 的数据格式,类似
[{
"type": "paragraph",
"children": [{
"type": "emotion",
"id": 51,
"children": [{
"text": ""
}]
}, {
"text": "来去也就剩下那么些人了。"
}]
}]
安卓 APP 应该怎么显示呢?不想用 webview 来处理
12 条回复 • 2021-08-19 20:55:42 +08:00
pigspy 1 天前
@learningman
slatejs 是一个 web 端的富文本框架,这个数据结构翻译成 html 就是 `<p><img src="./51">来去也就剩下那么些人了。<p>`,
麻烦一点的办法就是要手写一个解析器,把 slatejs 的数据格式先转换为 html,然后再用安卓的 HTML 工具类来转换为 TextView 可以显示的数据结构
我想问问有没有办法直接在安卓端显示这种数据
slatejs 是一个 web 端的富文本框架,这个数据结构翻译成 html 就是 `<p><img src="./51">来去也就剩下那么些人了。<p>`,
麻烦一点的办法就是要手写一个解析器,把 slatejs 的数据格式先转换为 html,然后再用安卓的 HTML 工具类来转换为 TextView 可以显示的数据结构
我想问问有没有办法直接在安卓端显示这种数据
ZoteTheMighty 16 小时 9 分钟前
直接 new 一个 webview 解析,这个 WebView 不需要展示, 只需要在 WebView 的 onLoadResource (好像是这个)里去拿解析的东西就好了, 然后退出销毁该 WebView 即可。
aristolochic 7 小时 21 分钟前
Slate 的官方序列化示例就是 switch 判断 children.type 对应输出 html 片段+递归;期间只用到了 Text 类作为判断是否为文本节点结束递归的依据。
所以其实对着它的 spec 很快就能写出来,也不必要用它的 Text 类判断是否为文本,文本节点特征很明显嘛。
如果 case 不多的话,为了这个需求就启动一个 WebView 是不是有些 Overkill 了
所以其实对着它的 spec 很快就能写出来,也不必要用它的 Text 类判断是否为文本,文本节点特征很明显嘛。
如果 case 不多的话,为了这个需求就启动一个 WebView 是不是有些 Overkill 了
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK