0
我有一個JSON字符串:如何從swift3中的JSON字符串中分別獲取鍵和值?
{
"messages": null,
"data": [
{
"id": 27,
"key": "ABC",
"value": "5",
"description": "Hi all"
},
{
"id": 28,
"key": "DEF",
"value": "1",
"description": "I am here"
}]
"status": 0
}
現在我需要拿到鑰匙的值,並與存在於核心數據的值更新它。 爲此,我現在用的是代碼:
func updateAllRecords(responseArray: [ApplicationSettingsDataResponse]) {
for settingsObject in responseArray {
if #available(iOS 10.0, *) {
let request = NSFetchRequest<ApplicationSettings>(entityName: "ApplicationSettings")
do {
let context = persistentContainer.viewContext
let searchResults = try context.fetch(request)
for settingsKeys in searchResults {
if settingsKeys.key == settingsObject.key {
settingsKeys.value = settingsObject.value
try context.save()
}
}
} catch {
print ("There was an error")
}
} else {
}
}
}
}
上午我在做這正確嗎?請查看此代碼。
你好你有什麼期望輸出 –