如何让Swift/Xcode控制台显示中文字符而不是unicode? [英] How can I get the Swift/Xcode console to show Chinese characters instead of unicode?
本文介绍了如何让Swift/Xcode控制台显示中文字符而不是unicode?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用以下代码:
import SwiftHTTP
var request = HTTPTask()
var params = ["text": "这是中文测试"]
request.requestSerializer.headers["X-Mashape-Key"] = "jhzbBPIPLImsh26lfMU4Inpx7kUPp1lzNbijsncZYowlZdAfAD"
request.responseSerializer = JSONResponseSerializer()
request.POST("https://textanalysis.p.mashape.com/segmenter", parameters: params, success: {(response: HTTPResponse) in if let json: AnyObject = response.responseObject { println("\(json)") } },failure: {(error: NSError, response: HTTPResponse?) in println("\(error)") })
Xcode控制台将其显示为响应:
The Xcode console shows this as a response:
{
result = "\U8fd9 \U662f \U4e2d\U6587 \U6d4b\U8bd5";
}
是否可以使控制台显示以下内容?:
Is it possible to get the console to show the following?:
{
result = "这 是 中文 分词 测试"
}
如果是这样,我需要怎么做才能实现它?
If so, what do I need to do to make it happen?
谢谢.
推荐答案
代替
println(json)
使用
println((json as NSDictionary)["result"]!)
这将打印正确的中文结果.
This will print the correct Chinese result.
原因:第一张照片将调用NSDictionary的调试描述,该描述不仅转义了中文字符.
Reason: the first print will call the debug description for NSDictionary which escapes not only Chinese chars.
这篇关于如何让Swift/Xcode控制台显示中文字符而不是unicode?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文