search

Home  >  Q&A  >  body text

objective-c - 给一个json体, 根据字段自动生成 一个model类出来 哪个大神知道这是怎么回事

我的意思是 给一个json , 它能给我建个类, 类里面直接匹配好属性.是第三方还是有方法 请大神指教

世界只因有你世界只因有你2763 days ago652

reply all(7)I'll reply

  • 大家讲道理

    大家讲道理2017-04-26 09:05:34

    The following reference
    MJExtension
    JSONModel

    You can also process Json yourself, convert json into a dictionary, and then use the dictionary to assign values ​​to the properties of the object (traverse the properties of the object and assign values)

    reply
    0
  • 淡淡烟草味

    淡淡烟草味2017-04-26 09:05:34

    As Blake said, first convert Json into a dictionary, and then convert the dictionary into a model. Regarding dictionary conversion, I just wrote an article a few days ago on the underlying principles of how the MJExtension framework converts a dictionary into a model. You can take a look at it. http: //weibo.com/p/1001603912111561547915
    Because it is mainly implemented through Runtime, you need to understand the basics of Runtime first

    reply
    0
  • 为情所困

    为情所困2017-04-26 09:05:34

    https://github.com/EnjoySR/ESJsonFormat-Xcode You can try this

    reply
    0
  • 黄舟

    黄舟2017-04-26 09:05:34

    To convert json into classes, you need to consider the following two issues
    1. How to generate beautiful class types
    2. What to do if the shape of each map in the array is different (usually it may mean inheritance

    However, the second point is the knowledge implicit in the semantics that is difficult to obtain from a json.

    reply
    0
  • ringa_lee

    ringa_lee2017-04-26 09:05:34

    I estimate that most people use third parties

    reply
    0
  • ringa_lee

    ringa_lee2017-04-26 09:05:34

    There is an Xcode plug-in that can achieve similar functions, called ESJsonFormat ● GitHub address
    It can automatically create classes and attributes based on the content of JSON strings.
    For details, please see the DEMO in GitHub.

    reply
    0
  • 过去多啦不再A梦

    过去多啦不再A梦2017-04-26 09:05:34

    xcode uses ESJsonFormat and IDEA uses GsonFormat.

    reply
    0
  • Cancelreply