Add tasks for all the new languages
This commit is contained in:
parent
9dc3c2bb62
commit
bba7bfd280
13208 changed files with 134745 additions and 0 deletions
19
Task/JSON/Swift/json.swift
Normal file
19
Task/JSON/Swift/json.swift
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
import Foundation
|
||||
|
||||
let jsonString = "{ \"foo\": 1, \"bar\": [10, \"apples\"] }"
|
||||
if let jsonData = jsonString.dataUsingEncoding(NSUTF8StringEncoding) {
|
||||
if let jsonObject : AnyObject = NSJSONSerialization.JSONObjectWithData(jsonData, options: .AllowFragments, error: nil) {
|
||||
println("NSDictionary: \(jsonObject)")
|
||||
}
|
||||
}
|
||||
|
||||
let obj = [
|
||||
"foo": [1, "Orange"],
|
||||
"bar": 1
|
||||
]
|
||||
|
||||
if let objData = NSJSONSerialization.dataWithJSONObject(obj, options: .PrettyPrinted, error: nil) {
|
||||
if let jsonString2 = NSString(data: objData, encoding: NSUTF8StringEncoding) {
|
||||
println("JSON: \(jsonString2)")
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue