Created
July 21, 2014 00:11
-
-
Save tLewisII/c1ac2c3ef7d1f509acc7 to your computer and use it in GitHub Desktop.
JSON Lens traversal in Swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let userjs: NSData = "{\"name\": \"max\", \"age\": 10, \"tweets\": [\"hello\"], \"attrs\": {\"one\": \"1\", \"more\": {\"stuff\": \"again\"}}}" | |
.dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false) | |
let val = JSValue.decode(userjs) | |
let traversal = JSValue.key("attrs") • JSValue.key("more") • JSValue.key("stuff") | |
let getIt = traversal.get(val) | |
let setIt = traversal.set(val, JSValue.JSString("bob")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment