当前位置:网站首页>Swiftyjson analyse les fichiers json locaux

Swiftyjson analyse les fichiers json locaux

2022-06-12 02:06:00 JH Cao

SwiftyJSON

1. LocalJSONDocumentation

[
    {
        "name": "hangge",
        "age": 100,
        "phones": [
            {
                "name": "Entreprises",
                "number": "123456"
            },
            {
                "name": "La famille",
                "number": "001"
            }
        ]
    },
    {
        "name": "big boss",
        "age": 1,
        "phones": [
            {
                "name": "Entreprises",
                "number": "111111"
            }
        ]
    }
]

2. demo

    override func viewDidLoad() {
        super.viewDidLoad()
        
        let path = Bundle.main.path(forResource: "testData", ofType: "json")!
        let testData = NSData(contentsOfFile: path)
        let json = try! JSON(data: testData! as Data)
        if let number = json[0]["phones"][0]["number"].string {
            print("Téléphone:",number)
        }
        
    }

原网站

版权声明
本文为[JH Cao]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/163/202206120206061763.html