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.

    评论

报告相同问题?

悬赏问题

  • ¥15 教务系统账号被盗号如何追溯设备
  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
  • ¥15 再不同版本的系统上,TCP传输速度不一致
  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式