从 Swift 中的 JSON 响应获取 JSON 对象
Get JSON Object from JSON Response in Swift
我想从 Swift 中的以下 JSON 响应中获取 LoginOperationResponseBody 密钥。
[
{
"LoginOperationResponseHeader": {
"ReponseCode": 1,
"ReponseType": "Success",
"ReponseDesc": "Login com successo"
},
"LoginOperationResponseBody": {
"UserName": "dev hélio africano monteiro querido varela",
"Email": "helio.varela@uniteltmais.cv",
"Perfil": "perfil_002",
"TipoCliente": "Particular",
"NIF": 0,
"PhotoId": 47212,
"NomeCompleto": "dev hélio africano monteiro querido varela",
"Number": 9100141,
"TipoClienteId": 1,
"TelefoneFixo": 0,
"UserID": 122,
"Morada": 0,
"ClientId": 22106,
"SessionId": "BBA72CDD-6BAA-4C22-AE95-8A674764CE7D",
"ClientNumber": 1000481
}
}
]
如果有人能帮助我,我将不胜感激。如果第一个数组对象上有一个键,我可以获取它,但是没有键我怎么能得到它。
提前致谢。
let loginOperationResponseBody = response[0]["LoginOperationResponseBody"]
我自己找的
我想从 Swift 中的以下 JSON 响应中获取 LoginOperationResponseBody 密钥。
[
{
"LoginOperationResponseHeader": {
"ReponseCode": 1,
"ReponseType": "Success",
"ReponseDesc": "Login com successo"
},
"LoginOperationResponseBody": {
"UserName": "dev hélio africano monteiro querido varela",
"Email": "helio.varela@uniteltmais.cv",
"Perfil": "perfil_002",
"TipoCliente": "Particular",
"NIF": 0,
"PhotoId": 47212,
"NomeCompleto": "dev hélio africano monteiro querido varela",
"Number": 9100141,
"TipoClienteId": 1,
"TelefoneFixo": 0,
"UserID": 122,
"Morada": 0,
"ClientId": 22106,
"SessionId": "BBA72CDD-6BAA-4C22-AE95-8A674764CE7D",
"ClientNumber": 1000481
}
}
]
如果有人能帮助我,我将不胜感激。如果第一个数组对象上有一个键,我可以获取它,但是没有键我怎么能得到它。 提前致谢。
let loginOperationResponseBody = response[0]["LoginOperationResponseBody"]
我自己找的