实现AnyObject到NSString问题

时间:2015-01-20 22:17:04

标签: ios swift

我试图将AnyObject值放到NSString并打印它但不幸的是它总是崩溃而没有显示EXC的原因。调试后我发现它在currStr之后崩溃了。那么请问我的问题在哪里?

      var lastRefresh: AnyObject = self.currDic["Response"]!.objectForKey("Datasource")!

      self.currStr = lastRefresh as NSString

      println("Data: \(self.curreStr)")

我的lastRefresh输出:

{
Cookie = 0nss1w45xzuocyqgvrjcmr31;
Message = "\U0130\U015flem Ba\U015farl\U0131";
Response =     {
    Datasource =         (
                    {
            Content = "";
            Date = "20.01.2015";
            Time = "08:32:22";
            Title = "Example1";
        },
                    {
            Content = "";
            Date = "20.01.2015";
            Time = "08:32:22";
            Title = "Example2";
        },

1 个答案:

答案 0 :(得分:2)

从您的评论中可以清楚地看到,您需要将lastRefresh对象转换为NSData才能在NSXMLParser中使用它。

NSLog Dictionary看起来像Arrayvar yourData : NSData = NSJSONSerialization.dataWithJSONObject(lastRefresh, options: NSJSONWritingOptions.PrettyPrinted, error: nil)! 。您可以使用以下方法将其转换为数据:

{{1}}