Giter VIP home page Giter VIP logo

runtime-dicttomodel's Introduction

runtime-dictToModel

runtime 字典转模型

将后台JSON数据中的字典转成本地的模型,我们一般选用部分优秀的第三方框架,如SBJSON、JSONKit、MJExtension、YYModel等。但是,一些简单的数据,我们也可以尝试自己来实现转换的过程。

快速使用

当我们的请求到的数据不是很复杂, 也不希望引入第三方框架的时候, 可以使用下这个分类, 来实现字典转模型.

1.根据请求数据, 创建对应的模型类, 并根据字典中的键值对定义对应的属性

  • 创建模型原则: 从外层到内存, 一个类型字典对应一个模型
  • 示例程序中, 根据plist, 创建了三个类: ShopItem , AttrModel , ListItemModel

runtime1

  • 注意: 定义的属性名和字典中的键名字一致.

2.在分类中导入最外层模型

runtime2

3.最外层类中导入 NSObject+EnumDict 分类

runtime3

4.遵守分类协议 ModelDelegate, 实现协议方法

runtime4

5.控制器中, 导入最外层模型 ShopItem.h , 解析数据遍历数组, 并字典转模型

runtime5

runtime-dicttomodel's People

Contributors

honkersk avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.