Swift iOS Pod。SimpleJSONParser 允许用户轻松地将 JSON 解析为任何 NSObject。
导入
import SimpleJSONParser
Cocoapods
pod 'SimpleJSONParser'
1) 这里是一个如何使用它的例子
let dictionary = NSMutableDictionary()
dictionary.setValue("sdfsdf", forKey: "uniqueID")
dictionary.setValue("valera", forKey: "name")
dictionary.setValue("34", forKey: "age")
let dictionary2 = NSMutableDictionary()
dictionary2.setValue(["34", "56", "876"], forKey: "ids")
dictionary.setValue(dictionary2, forKey: "test2")
let test = TestClass.fromJson(dictionary)
2) 测试模型
import Foundation
public class TestClass: NSObject {
var uniqueID: String?
var name: String?
var age: Int = 0
var test2: TestClass2?
}
public class TestClass2: NSObject {
var ids: [String] = []
}