September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
|
|
@ -1,19 +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)")
|
||||
}
|
||||
if let jsonData = jsonString.data(using: .utf8) {
|
||||
if let jsonObject: Any = try? JSONSerialization.jsonObject(with: jsonData, options: .allowFragments) {
|
||||
print("Dictionary: \(jsonObject)")
|
||||
}
|
||||
}
|
||||
|
||||
let obj = [
|
||||
"foo": [1, "Orange"],
|
||||
"bar": 1
|
||||
]
|
||||
"foo": [1, "Orange"],
|
||||
"bar": 1
|
||||
] as [String : Any]
|
||||
|
||||
if let objData = NSJSONSerialization.dataWithJSONObject(obj, options: .PrettyPrinted, error: nil) {
|
||||
if let jsonString2 = NSString(data: objData, encoding: NSUTF8StringEncoding) {
|
||||
println("JSON: \(jsonString2)")
|
||||
}
|
||||
if let objData = try? JSONSerialization.data(withJSONObject: obj, options: .prettyPrinted) {
|
||||
if let jsonString2 = String(data: objData, encoding: .utf8) {
|
||||
print("JSON: \(jsonString2)")
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue