var json : JSON = []
var data = [
"name":"asd",
"age":"23"
]
for (key,value) in data {
json[key] = value
}
error: cannot assign value of type string to a value of type json
var json : JSON = [:] // data is a Dictionary
var data = [
"name":"asd",
"age":"23"
]
for (key,value) in data {
json[key].stringValue = value // or json[key] = JSON(value)
}
This should work.
Out of curiosity why does this error occur? What about wrapping it in a for loop forces us to explicitly type it to a string?
Most helpful comment
This should work.