【发布时间】:2018-05-23 16:55:17
【问题描述】:
我有以下 var 我需要更改/更新例如键 'end' 的 'dateTime' 值与用户拥有的值放进去。
var calendarEvent = [
"subject": "Let's go for lunch",
"body": [
"contentType": "HTML",
"content": "Does late morning work for you?",
],
"start": [
"dateTime":"2017-12-10T12:55:00",
"timeZone": "W. Europe Standard Time"
],
"end": [
"dateTime": "2017-12-10T14:00:00",
"timeZone": "W. Europe Standard Time"
],
"location": [
"displayName": "Antwerpen"
],
"attendees": [],
] as [String: AnyObject]
假设我们不关心用户输入 - 因为它只是一个字符串 - 并且只想用单词 'yea boi' 替换该值。
我该怎么做?
【问题讨论】:
-
使用为您的程序设计的数据类型,而不是字典。
-
我需要将 JSON 发布到 api。字典在所需的类中格式化为 JSON。
-
我只需要知道如何更新这个字典中某个键的值。
-
使用专为您的程序设计并且可以序列化为 JSON 的数据类型。如果你正在使用 Swift 4 this is nearly automatic.
标签: swift dictionary nested