【发布时间】:2019-08-19 18:20:17
【问题描述】:
我正在尝试将 getstream 集成到我的应用程序中,我需要一些帮助来解决我遇到的 jsonDecode 错误。
以下是我采取的步骤:
1.手动创建一个新的订阅组allevents
2.我的后端能够在所有事件中创建一个名为 bday_11 的新提要。
我从后端创建了 2 个用户
ameet和ramya并让他们添加活动。然后使用follow api,我让bday_11同时关注ameet和ramya。当我手动执行 bday_11.get() 时,我能够看到预期的活动
In [86]: bday_11.get()
Out[86]:
{u'duration': u'22.46ms',
u'next': '',
u'results': [{u'actor': u'chris',
u'foreign_id': u'picture:10',
u'id': u'a0febe54-bfad-11e9-9361-0a286b200b2e',
u'message': u'Beautiful bird!',
u'object': u'picture:10',
u'origin': u'user:ameet',
u'target': '',
u'time': datetime.datetime(2019, 8, 15, 22, 40, 6, 280764),
u'verb': u'add'},
{u'actor': u'chris',
u'foreign_id': u'picture:10',
u'id': u'96919914-bfad-11e9-933c-0a286b200b2e',
u'message': u'Beautiful bird!',
u'object': u'picture:10',
u'origin': u'user:ramya',
u'target': '',
u'time': datetime.datetime(2019, 8, 15, 22, 39, 48, 788252),
u'verb': u'add'}]}
现在在客户端,这就是我在 AppDelegate 上初始化客户端的方式。这是使用我们的 Feed 参数对您现有的演示项目进行的修改
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Setup Stream Client.
Client.config = .init(apiKey: "ehs4s58m3u43",appId: "57260",token:FEED_TOKEN)
//Client.config = .init(apiKey:apiKey, appID:appID,token:FeedToken)
// Setup Stream user.
Client.shared.getCurrentUser(typeOf: GetStreamActivityFeed.User.self) { result in
// Current user is ready. Load timeline feed.
if result.error == nil, let viewController = self.window?.rootViewController as? ViewController {
viewController.reloadData()
}
}
return true
}
这是我尝试阅读创建的提要的方式。
override func viewDidLoad() {
// Setup a timeline feed presenter.
let timelineFlatFeed = Client.shared.flatFeed(feedSlug: "allevents",userId: "bday_11")
presenter = FlatFeedPresenter<GetStreamActivityFeed.Activity>(flatFeed: timelineFlatFeed,
reactionTypes: [.likes, .comments])
super.viewDidLoad()
setupTextToolBar()
subscribeForUpdates()
}
我似乎在演示者中收到以下错误:
❌ jsonDecode("The data couldn’t be read because it isn’t in the correct format.", Optional(Swift.DecodingError.typeMismatch(Swift.Dictionary<Swift.String, Any>, Swift.DecodingError.Context(codingPath:
[CodingKeys(stringValue: "results", intValue: nil), _JSONKey(stringValue: "Index 0", intValue: 0),
CodingKeys(stringValue: "actor", intValue: nil)], debugDescription: "Expected to decode Dictionary<String, Any> but found a string/data instead.", underlyingError: nil))), 667 bytes)
有人可以帮忙吗?
【问题讨论】:
-
看起来您的响应 JSON 无效。它实际上是在键和值之前返回 'u' 字符吗?另外,你能分享你解码 JSON 的结构吗?
标签: ios getstream-io