Small knowledge, big challenge! This paper is participating in theEssentials for programmers”Creative activities.
preface
JSON to model is always a hot topic in mobile development.
There are tons of JSON options, but with one quick tool, you can do it with a click.
Today I will introduce you to the JSON to model tool that I often use in my development.
quicktype
This is a JSON model conversion tool I use most at present, mainly used for Swift and Dart model conversion. Of course, it can convert the language is very rich, you can choose according to need.
For Swift, conversion is made directly through Codable protocol, which is convenient and time-saving. The conversion quality is also recommended.
As we all know, since Dart does not allow reflection in Flutter, transmodel is basically a very pure Map transformed by key-value pairs. Quicktype certainly does this very well, but there are sharper tools for Flutter development. I’ll talk about that later.
Another very friendly aspect of quicktype is that it has support for Web pages, Mac, and VSCode, so you can install and use it according to your needs.
Quicktype web page
quicktype for Mac
quicktype for VSCode
JSONExport
Before QuickType, I have been using this software to do JSON model conversion in Swift:
As you can see, the related transformation options are basically related to the Transformation of Apple development side, which is a relatively simple transformation tool.
The unfortunate thing about this software is that it hasn’t been updated since a Release in 2018.
If the JSON hierarchy is too deep, conversion problems can also occur.
In addition, this software is written by Swift open source software, if you like, you can star a oh.
Lot of JSONExport
ModelEnd
In fact, AS for the JSON model in OC, I personally prefer to use YYModel for the following two reasons:
-
YYModel has less coupling and integration files, so it can be said that it is protocol-oriented to extend the model through YYModel protocol.
-
YYModel is highly efficient, which IS compared with YY god in the article. I don’t have to explain it.
However, as far as I know, there is no tool that can transfer model through YYModel protocol in one step.
For most OC models, we had to cut the code and then follow the YYModel protocol.
This ModelEnd is very pure, so pure that it only declares properties in.h, and no other method declarations, and the.m file is blank:
It is this kind of pure, for our YYModel transformation to avoid meaningless deleting code operations, coupled with the quick operation of code blocks, we can quickly carry out JSON to model.
ModelEnd url
OC’s JSON conversion model is worse than Swift’s Codable conversion model.
FlutterJsonBeanFactory
This plugin is ideal for JSON model transfer in Flutter development. By scripting, centralized management, it is possible to manage models and implement generic downscaling and base class models.
This plug-in is installed and used based on AS.
FlutterJsonBeanFactory plugin url
Reference Documents:
Swift: JSON parsing
Swift: JSON parsing
The FlutterJsonBeanFactory plugin is used with JSON
conclusion
As for the current development, I personally prefer to use QuickType for JSON model conversion. It has many software platforms and a wide range of programming languages for conversion.
ModelEnd is recommended if YYModel is used for model-conversion in OC. YYModel, YYDS in OC.
FlutterJsonBeanFactory is a good JSON to Model plugin for Flutter development.
We’ll see you next time.