douxiexie3574 2019-05-15 07:50
浏览 116

Swift,php和unicode字符

I am using a url request to receive data from MySQL. The data is received in a JSON format. This data also includes unicode characters (for example greek letters).

Then, in Swift, I am using JSONSerialization like this:

if let json = try JSONSerialization.jsonObject(with: data!, options: []) as? [String: Any] {

The keys of json are number indices. Then I take a nested dictionary like this:

let dictionary = json[key] as? [String: Any]

Then I assign:

var content = dictionary!["content"] as! String

This content has unicode characters inside it.

Unicode characters appear like this (if I print dictionary): \U03b1 (for the greek letter Alpha).

The problem is that Swift cannot read those characters because Swift expects unicode characters to be like this: \u{03b1}.

The value of content is an empty string: ""

How can I solve this? Either have PHP send those characters in the way the Swift "understands" them, or having Swift decoding the incoming data in the proper way.

Any ideas?

Thanks!

  • 写回答

1条回答

  • dongxun2903 2019-05-15 11:15
    关注

    I do have the same kind of issue for multiple currency symbols. API team is passing now '\u0024' and it has resolved issue in Swift. May be you can try same from API side.

    评论

报告相同问题?

悬赏问题

  • ¥20 求数据集和代码#有偿答复
  • ¥15 关于下拉菜单选项关联的问题
  • ¥15 如何修改pca中的feature函数
  • ¥20 java-OJ-健康体检
  • ¥15 rs485的上拉下拉,不会对a-b<-200mv有影响吗,就是接受时,对判断逻辑0有影响吗
  • ¥15 使用phpstudy在云服务器上搭建个人网站
  • ¥15 应该如何判断含间隙的曲柄摇杆机构,轴与轴承是否发生了碰撞?
  • ¥15 vue3+express部署到nginx
  • ¥20 搭建pt1000三线制高精度测温电路
  • ¥15 使用Jdk8自带的算法,和Jdk11自带的加密结果会一样吗,不一样的话有什么解决方案,Jdk不能升级的情况