c++ - 如何从 QString 中获取 unicode 字符?
问题描述
所以希望这比我想象的要简单。我正在将 JSON 数据读取到我的应用程序中,并以 QString 的形式出现一个条目"\uf103"
,它实际上由字符'\\'
、'u'
、'f'
、'1'
、'0'
和表示'3'
。我将如何实际将其转换为由代码表示的 unicode 字符\uf103
?我经历了许多似乎提出类似问题的线程,但没有一个有直接的答案。
对于上下文,我只是想将此字符显示为按钮的文本。
我的解析例程如下所示:
QString infoPath = QDir::currentPath() + "/resources/fonts/fontawesome/unicode_info.json";
QJsonObject fontAwesome = JsonReader(infoPath).getContentsAsJsonObject();
QString fa = JsonReader::getJsonValueAsQString(fontAwesome);
if (!fontAwesome.contains(fontAwesomeIcon)) {
qDebug() << "Error, font awesome icon not found";
#ifdef DEBUG_MODE
throw("Error, font awesome icon not found");
#endif
}
QString unicode = fontAwesome.value(fontAwesomeIcon).toObject().value("unicode").toString();
字符串unicode
是感兴趣的主题。原始 JSON 看起来像这样,只是更大:
{"500px": {"unicode": "\\uf26e", "styles": ["brands"], "label": "500px"}, "accessible-icon": {"unicode": "\\uf368", "styles": ["brands"], "label": "Accessible Icon"}, "accusoft": {"unicode": "\\uf369", "styles": ["brands"], "label": "Accusoft"}, "acquisitions-incorporated": {"unicode": "\\uf6af", "styles": ["brands"], "label": "Acquisitions Incorporated"}}
所以,问题是我首先从双斜杠开始。如果有办法以这种方式获取 unicode 字符,我也愿意在 python 中预处理这个 JSON 的方法。
解决方案
我通过 python 处理步骤解决了这个问题,在每个有问题的字符串上运行以下行:
problem_string = "\\u2095"
good_string = bytes(problem_string, "ascii").decode('unicode-escape'),
推荐阅读
- asp.net-mvc - ASP.NET MVC Razor 在用户编辑输入文件时捕获 textchange 事件
- video - 如何为基于 Flutter 构建的应用录制的视频添加时间戳
- c# - 实体框架 - 外键对象未映射到抽象类
- spring-boot - 从单个 SQSListener 监听多个 AWS SQS
- flutter - 使用 Flutter 查询 Firestore 中的子集合
- reactjs - 我怎么知道渲染原因是在反应钩子函数中改变了属性还是改变了状态?
- microsoft-graph-api - Places Room List API 返回缓存数据
- paypal - 贝宝自适应支付的未来会是什么?
- python - Python - 将 JSON 附加到主分支
- css - 当我尝试在我的 jsp 中插入 css 时,找不到我的 Spring DispatcherServlet。为什么?