flutter - Flutter 将包含 \n 的 json 数据转换为新行
问题描述
我的 API 发送一个 json 格式如下:
{ status: false, message: 'This is an error \n\n with multi line!' }
我想显示消息并应用 json 中设置的新行。
我正在使用 Dio 包,并返回如下信息:
Response response = await Dio().post(...)
String message = response.data['message'];
这会按字面意思打印This is an error \n\n with multi line!
而不是打印:
这是一个错误
多线!
如果我手动输入String message = 'This is an error \n\n with multi line!'
效果很好。
在我看来,我必须使用replaceAll
函数,但我不知道要替换什么。
解决方案
尝试使用这个
replaceAll('\\n', '\n');
推荐阅读
- linux - For 循环的双变量展开
- php - 保存元框值不起作用 [WP-PHP]
- angular - Angular 将变量传递给 HTTP GET
- ios - 将参数从 CollectionViewController 传递到 CollectionViewCell
- c# - 即使安装了 .net 核心,也找不到它。我应该重新启动我的 Mac 以使用 microsoft stack 吗?
- java - Hadoop 映射器直接写入输出。(Reducer 写入 mapper 的输出)
- javascript - 如何使用插件 jscrollpane 修复thead?
- php - 如何以 XML 版本和编码输出 (PHP)
- asp.net-mvc - 显示上传文件列表
- visual-studio-code - 是否可以在 VSCode 中放置代码折叠图标?