I don't know the type to call json in Swift.

Asked 2 years ago, Updated 2 years ago, 90 views

swift4
xcode 9.4.1

I don't know the "type" when declaring the type of json in the swift.
In the case of this json, what type should I write?

The json is as follows:

{
    "calendar": {
        "month": {
            "jp": {
                "1"—"January"
            },
            "en": {
                "1" : ""
            }
        }
    }
}

And I wrote some code for loading json in swift.

let path: String=Bundle.main.path (forResource: "language", ofType: "json")!
    let fileHandle: FileHandle=FileHandle(forReadingAtPath:path)!
    let data —NSData=fileHandle.readDataToEndOfFile() as NSData
    let json=NSString(data:data as Data, encoding:String.Encoding.utf8.rawValue)!
    do{
        Let personalData: Data=json.data(using:String.Encoding.utf8.rawValue)!

        // This part is not Any, but I want to make it a model when the above Json is changed to a dictionary type array.
        Let items=try JSONSERIALIZATION.jsonObject(with:personalData) as!Any 
        print(items)
    } catch{
    }

xcode json swift4

2022-09-30 16:50

1 Answers

as!Any

not

as![String:Any]

Why don't you take them out in order?


2022-09-30 16:50

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.