最新消息:20190717 VPS服务器:Vultr新加坡,WordPress主题:大前端D8,统一介绍入口:关于

[已解决]swift中把 NSDictionary转换为JSON

JSON crifan 799浏览 0评论

已有代码:

    func handleRemoteNotification(remoteInfo:NSDictionary) {
        print("handleRemoteNotification remoteInfo=\(remoteInfo)")
       
        if UIApplication.sharedApplication().applicationState == UIApplicationState.Active {
            print("not handle remote notification for app is active running")
        } else {
            print("applicationState=\(UIApplication.sharedApplication().applicationState)")
           
            let messageDict = JSON(remoteInfo)
            SingletonConversationTVC().processSingleMessageDict(messageDict)
        }
    }

中,想要把NSDictionary类型的remoteInfo,转换为(SwiftyJSON的)JSON

搜:

swift NSDictionary to SwiftyJSON

SwiftyJSON/README.md at master · SwiftyJSON/SwiftyJSON · GitHub

SwiftyJSON – code4swift|swift迷

swift – NSDictionary > JSON String using SwiftyJSON – Stack Overflow

好像是可以像上述代码中直接传入NSDictionary??

是的,代码中直接就可以了。

改为:

    func handleRemoteNotification(remoteNotification:NSNotification) {
        print("handleRemoteNotification remoteNotification=\(remoteNotification)")
        if let userInfoDict = remoteNotification.object {
            print("userInfoDict=\(userInfoDict)")
           
            if UIApplication.sharedApplication().applicationState == UIApplicationState.Active {
                print("not handle remote notification for app is active running")
            } else {
                print("applicationState=\(UIApplication.sharedApplication().applicationState)")
                SingletonConversationTVC().updateAllConversation()
            }
        }
    }

即可。

转载请注明:在路上 » [已解决]swift中把 NSDictionary转换为JSON

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
56 queries in 0.097 seconds, using 18.68MB memory