-
Notifications
You must be signed in to change notification settings - Fork 3.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Updating a json #60
Comments
You need to fully rewrap your edited object in JSON enum or propose another genius solution for editing SwiftyJSON :) |
Try this fork: k06a/SwiftyJSON/tree/editing I think this functionality will be implemented in SwiftyJSON soon, method names and form of calls may be changed. |
Following NSJSONSerialization.JSONObjectWithData there are mutable data in JSON, but the first thing is set the data safety. If I do not know the type of the data, I can't set the data to unknown type. If I do know the type, I can set the data like this: var newJson: JSON?
if let dictionary = json[999]["user"].dictionary {
//It's safe
var newObject = json.array
(newObject[999] as Dictionary<String, AnyObject>)!["user"] = "new user name"
newJson = JSON(object: newObject)
} else {
//do something where dictionary is not the Dictionary<String, Anyobject>
} |
Hi @k06a, thanks for the reply :-) I assume you're referencing: I could find any other usage (tests or documentation)... |
@yelled3 just added new syntax:
It is mush shorter and readable :) |
@k06a @yelled3 var json = JSON(object: object)
value[0]["id"] = "12345667"
println(value[0]["id"]) // print "1234567"
value[0]["id"] = "789012"
println(value[0]["id"]) // print "789012" var json1:JSON = 12345677
var json2:JSON = "hello"
var json3:JSON = [1,2,3]
var json4:JSON = ["name":"tangplin",list:[1,2,3,4]]
//Update
json1= 456
json2= "www"
json3[0] = 4
json4["name"] = "Jack" It's very cool! |
Looks most native way to update a nested JSON. Are you using mutable collections inside JSON enum? |
Hi, is there a way to update a JSON object? e.g
The text was updated successfully, but these errors were encountered: