【发布时间】:2014-06-04 16:28:17
【问题描述】:
我有一个 NSArray 作为 Web 服务 (JSON) 请求的结果。
如果我打印 NSLog("%@", jsonResult) 数组,它会正确显示:
(
{
text = “Some text”;
coordinates = “11.333345 - 09.33349”;
}
{
text = “Some text2”;
coordinates = “11.333345 - 09.33349”;
}
{
text = “Some text3”;
coordinates = “11.333345 - 09.33349”;
}
…
)
但是,如果我尝试使用以下函数访问 NSArray 中每个条目的键“文本”的值,我总是会得到如下输出:
Text )r'ì• (instead of "Some text2, 3 ....")
所以我认为类型不匹配,但我不知道如何找出问题所在。 在 Objective-C 中它工作得很好。
func getResult(){
self.webService.getResult({ jsonResult in
jsonResult!.enumerateObjectsUsingBlock({ object, index, stop in
var txt : NSString = object.valueForKey("text") as NSString
NSLog("Text %s", txt)
})
NSLog("Ready %@", jsonResult!)
});
}
有什么想法吗?
更新 1
我发现,如果我只使用 NSObject 而不是 NSString 它会正确显示文本
var txt : NSObject = object.valueForKey("text") as NSObject
NSLog("%@", txt)
但无论如何,我必须将该 NSObject 对象转换为 NSString 或 String,以显示...
希望显示字符串的编码是什么……或者如何转换这个 NSObject??
【问题讨论】: