Skip to content

Latest commit

 

History

History
69 lines (42 loc) · 1.73 KB

README.md

File metadata and controls

69 lines (42 loc) · 1.73 KB

json2swift

auto convert json string to swift struct.中文介绍

demo


  • How to use?

    OS X app

      1. Input json to left
      1. click "convert=>"
      1. Copy the result Parameters statement:
      • ObjectMapper: Simple JSON Object mapping written in Swift. If this is selected, result will auto add func mapping

      • name: the name of the result, default is "Result"

      • prefix: the prefix of each struct name, default is empty.

    python script

      1. open Terminal, cd to Main.py
      1. Copy json string to File named "jsons.txt"
      1. Python3 Main.py
      1. ResultModel.swift is the result


Other

CocoaPython: a fast way to use python with Cocoa. we can use CocoaPython.swift like this:

// python path
guard let aPath = Bundle.main.path(forResource: "Parse", ofType: "py") else { return }

// args: python accept paras
// block: complete block
let script = CocoaPython(scrPath: aPath, args: [""]) { [weak self] in
    print($0) // python's return
    print($1) // python's Error
}

script.spliPara = "$" // the multi results's split Character, if not set, all the results is in result[0]. 
script.runAsync()
// or script.runAsync(asyncComlete: false) // the complete block call in global async
// or script.runSync() // run in current thread

Reference