Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

嵌套解析出错 #39

Closed
MoonightIce opened this issue Jan 3, 2020 · 2 comments
Closed

嵌套解析出错 #39

MoonightIce opened this issue Jan 3, 2020 · 2 comments

Comments

@MoonightIce
Copy link

模型

struct ChatRoomModel: Convertible {    
     var lastMessage: String = ""
     var lastMessageTime: NSNumber = 0
     var pkid: NSNumber = 0
     var unreadNoticeCount: NSNumber = 0

}
struct WorkShopsModel: Convertible {   
    var chatRoom:   ChatRoomModel?
    var imgUrl:     String = ""
    var isMine:     NSNumber = false
    var pkid:       NSNumber = 0
    var unsignined: NSNumber?
    var status:     NSNumber = 0
    var title:      String = ""
    var regCount:   Int?
    var tbString:   String?
    var teString:   String?

}

数据

            let json  =
                        """
                        {
                    "chatRoom": {
                        "dataSourceName": "x",
                        "last_message": "",
                        "last_message_time": 1567578912000,
                        "pkid": 2,
                        "unread_notice_count": 0
                    },
                    "dataSourceName": "x",
                    "img_url": "",
                    "is_mine": true,
                    "pk_chatroom": 2,
                    "pkid": 3,
                    "reg_count": 1,
                    "status": 1,
                    "tbString": "2019-01-30",
                    "teString": "2019-09-28",
                    "title": "",
                    "unsignined": true
                }
                """

chatRoom 字段解析出来是 nil

@MoonightIce
Copy link
Author

我设置一个全局

ConvertibleConfig.setModelKey { property in
         property.name.kj.underlineCased()
 }

数据中的下划线字段映射到模型正确
is_mine img_url
但同时
chatRoom tbString
这类字段就会映射出错

将全局设置注销后,上诉两类字段映射情况刚好相反。

@CoderMJLee
Copy link
Collaborator

不好意思,最近比较忙,刚看到问题

问题所在:因为设置了全局转下划线,遇到chatRoom、tbString,会去字典中查找chat_room、tb_string,所以转换失败

解决方案:如果chat_room、tb_string不存在,会利用chatRoom、tbString重新去字典中查找

最新的1.1.2版本已经增加这个功能

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants