alibaba / alibaba/HandyJSON

模型初始化的时候,加载沙盒json文件转成字典,然后字典转模型,转换失败,这种情况如何字典转模型呢

Open
#254 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Swift
Stars
4.3k
Forks
677
PR merge metrics
No merged PRs in 30d

Description

required init() {
super.init()

//1.加载本地沙盒存储的用户模型,data反序列化成字典
guard let path = userPathName.zw_appendDocumentDir(),
let data = NSData(contentsOfFile: path),
let dic = try? JSONSerialization.jsonObject(with: data as Data, options: []) as? [String:Any]
else {

return
}

//2.字典转模型
if let user = ZWUser.deserialize(from: dic) {
print(user)
}


}
这种情况字典转模型失败,为什么不能象yymodel一样直接self.yy_modelSet(with: dic),这种情况如何字典转模型呢?

Contributor guide

No contributing guide indexed for this repository

Research direction

Begin with the required init() example and trace ZWUser.deserialize(from: dic), then compare its behavior with the referenced yy_modelSet(with:) call. Reproduce the failed conversion using the shown sandbox JSON path and dictionary; done means the cause is confirmed and the supported dictionary-to-model path is documented or verified.

Written by the indexing model from the issue text.

Assessment

Tech stack
swift
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.