Comments (9)
You need to fully rewrap your edited object in JSON enum or propose another genius solution for editing SwiftyJSON :)
from 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.
from swiftyjson.
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>
}
from swiftyjson.
Hi @k06a, thanks for the reply :-)
I assume you're referencing:
https://github.com/k06a/SwiftyJSON/blob/editing/Source/SwiftyJSON.swift#L229-L263
I could find any other usage (tests or documentation)...
from swiftyjson.
@yelled3 you can see example of usage in my PR: #61
from swiftyjson.
@yelled3 just added new syntax:
let json2 = json.updated((0,"user","name"), newValue: JSON(object: "Anton Bukov"))
It is mush shorter and readable :)
from swiftyjson.
@k06a @yelled3
I will release the 2.0.0 version of SwiftJSON in a few days, like this:
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!
from swiftyjson.
Looks most native way to update a nested JSON. Are you using mutable collections inside JSON enum?
from swiftyjson.
Done in 59996b2 748ef28 eb7cc54 at develop branch.
It's need more test before merge into the master branch.
from swiftyjson.
Related Issues (20)
- <!-- HOT 2
- Could not find module 'SwiftyJSON' for target 'x86_64-apple-ios-simulator'; found: arm64, arm64-apple-ios-simulator HOT 6
- Crash on iOS 15 HOT 5
- Please assist urgent HOT 1
- Data parsing get is null
- Jcharly🤔
- What is SwiftJSON latest version as per current date(20/06/022 stable version only) which supports iOS 15+ AND what is Alamofire version which supports iOS 15+, both should supports iOS 15 and it's Above version.
- How to test if a property exists on a JSON object? HOT 1
- How to read emojis in JSON
- Warning that in Swift 6 will be an error HOT 13
- Type 'Any' is not optional, value can never be nil; this is an error in Swift 6 HOT 2
- How to update a field of a SwiftyJSON object
- New version release - When? HOT 11
- Json cert
- Recommended way to conform `JSON` to `Hashable` HOT 4
- Empty dictionary object cannot insert data HOT 2
- unwrap crash HOT 1
- Privacy manifest required by Apple HOT 9
- Errors in readme HOT 1
- Privacy Manifest HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from swiftyjson.