Cocos2d-x解析XML文件,解决中文乱码

论坛 期权论坛 脚本     
匿名技术用户   2021-1-4 12:38   75   0

身处大天朝,必须学会的一项技能就是解决中文显示问题。这个字符问题还搞了我一天,以下是个人解决乱码问题的实践结果,希望可以给其他人一些帮助

读取xml文件代码:

1 CCDictionary* message = CCDictionary::createWithContentsOfFile("chinese.xml");    //读取xml文件,文件在Resources目录下
2     auto helpTitleKey = message->valueForKey("helpTitle");    //根据key,获取value
3     const char* helpTitle = helpTitleKey->getCString();    //将value转化为字符串

xml文件:

 1 <?xml version="1.0" encoding="utf-8"?>
 2 <dict>
 3   <key>helpTitle</key>
 4   <string>帮助信息</string>
 5   
 6   <key>score</key>
 7   <string>分数</string>
 8   
 9   <key>helpMessage</key>
10   <string></string>
11  </dict>

运行结果:

cocos2dx新手+菜鸟一枚,有改进之处,还请指点。

<?xml version="1.0" encoding="utf-8"?>
<dict>
<key>helpTitle</key>
<string>帮助信息</string>

<key>score</key>
<string>分数</string>

<key>helpMessage</key>
<string></string>
</dict>

转载于:https://www.cnblogs.com/HuangWj/p/5180229.html

分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:7942463
帖子:1588486
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP