how to pase JSON in Swift
来源:互联网 发布:商业数据分析 编辑:程序博客网 时间:2024/06/04 06:16
http://roadfiresoftware.com/2015/10/how-to-parse-json-with-swift-2/
Example:
{
“blogs”: [
{
“needspassword”: true,
“id”: 73,
“url”: “http://remote.bloxus.com/“,
“name”: “Bloxus test”
},
{
“needspassword”: false,
“id”: 74,
“url”: “http://flickrtest1.userland.com/“,
“name”: “Manila Test”
}
],
“stat”: “ok”
}
var names = String
do {
let json = try NSJSONSerialization.JSONObjectWithData(data, options: .AllowFragments)
if let blogs = json["blogs"] as? [[String: AnyObject]] { for blog in blogs { if let name = blog["name"] as? String { names.append(name) } }}
} catch {
print(“error serializing JSON: (error)”)
}
print(names) // [“Bloxus test”, “Manila Test”]
if let blogs = json[“blogs”] as? [[String: AnyObject]] {
// if we get “blogs” from the JSON
// AND we can cast it to an array of dictionaries
// then this code will execute
}
for blog in blogs {
if let name = blog[“name”] as? String {
names.append(name)
}
}
- how to pase JSON in Swift
- How to parse JSON in Java
- How to get Json in Android
- How to use json with as3corelib in flex( JSON )
- How to convert XML to JSON in ASP.NET C#
- How to convert XML to JSON in ASP.NET C#
- How to build a nice Hamburger Button transition in Swift
- How to play video with AVPlayerViewController (AVKit) in Swift
- how to make Completion Handlers and use it in Swift
- how-to-use-swift
- How to add net.sf.json-lib dependendy in Maven
- How to get the JSON results in ExtJS
- How to overcome “datetime.datetime not JSON serializable” in python?
- How to read and write JSON files in Java(Gson)
- How to read Json file or text file in Spark
- How to use fasterxml Jackson JSON serialization in Spring 4
- How to import a C library in Swift using the Swift Package Manager
- How to parse JSON
- iOS issues
- Installation with CocoaPods
- spark-sql 性能测试
- 我要玩石器多开的攻与防和外挂 ③
- FCM issues (Firebase Cloud Message)
- how to pase JSON in Swift
- 关于预处理、宏和函数、编译链接的理解
- Oracle数据库之一_多表查询
- JS 对象
- 206. Reverse Linked List
- 冒泡排序(Bubble Sort)
- 快速排序(Quick Sort)
- 简单选择排序(Simple Selection Sort)
- 堆排序(Heap Sort)