XcodeプラグインLCJSOnFormatter:JSON回転モデルswift版

2863 ワード

LCJSONFormatter
これは純粋なswiftバージョンのJSON回転モデルツールです.MJExtensionのようにswiftではArgoを使います
サンプルJSON 1は、辞書で始まります.
{
    "id": 1, 
    "name": "JohnSnow", 
    "dic": [
        {
            "key": "hello world", 
            "value": "where are you"
        }, 
        {
            "key": "hello world", 
            "value": "where are you"
        }
    ], 
    "commentsInfo": {
        "id": 100, 
        "value": "good man"
    }, 
    "price": 4.39, 
    "woman": false, 
    "optionalString": null, 
    "optionalArray": [ ]
}

サンプルJSON 2は、配列で開始します.
[
    {
        "id": 1, 
        "name": "JohnSnow", 
        "dic": [
            {
                "key": "hello world", 
                "value": "where are you"
            }, 
            {
                "key": "hello world", 
                "value": "where are you"
            }
        ]
    }, 
    {
        "id": 1, 
        "name": "JohnSnow", 
        "dic": [
            {
                "key": "hello world", 
                "value": "where are you"
            }, 
            {
                "key": "hello world", 
                "value": "where are you"
            }
        ]
    }
]

使用
AlcatrazでLCJSOnFormatterを検索し、Xcodeを再起動します.
swiftファイルでLCJSOnFormatterウィンドウを呼び出します.上のJSONを貼り付けます.途中で車に戻ればいいです.
最後に、変換されたファイルは次のとおりです.
//    1,     
import UIKit

import Argo
import Curry

struct LCJSONFormatterDemo: Decodable { 
 
    let optionalString: String?
    let id: Int
    let price: Double
    let optionalArray: [String]?
    let dic: [Dic]
    let commentsInfo: Commentsinfo
    let woman: Bool
    let name: String 

    static func decode(json: JSON) -> Decoded {
          return curry(self.init)
         json  json  json  json  json  json  json  json  Decoded {
          return curry(self.init)
         json  json  Decoded {
          return curry(self.init)
         json  json 
//    2,     
import UIKit

import Argo
import Curry

struct LCJSONFormatterDemo: Decodable { 
 
    let lcArray: [Lcarray] 

    static func decode(json: JSON) -> Decoded {
          return curry(self.init)
         json  Decoded {
          return curry(self.init)
         json  json  json  Decoded {
          return curry(self.init)
         json  json