-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathHighLightJsonParser.swift
80 lines (60 loc) · 2.31 KB
/
HighLightJsonParser.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
//
// HighLightJsonParser.swift
// OpenHouseOneFive
//
// Created by Thanat Jatuphattharachat on 10/30/2558 BE.
// Copyright © 2558 Thinc. All rights reserved.
//
import UIKit
import SwiftyJSON
class HighLightJsonParser: NSObject {
let HIGHLIGHT_JSON_FILE = "highlight"
var jsonObj: JSON = []
func serializeJSON() -> [[String]] {
var arrDetail : [[String]] = [[String]]()
loadJSONFile();
for var jsonDetail:JSON in jsonObj["open_house_highlight"].array!{
var row = [String]()
var artPic = jsonDetail["Artwork_name"].stringValue
var lat = jsonDetail["Latitude"].stringValue
var long = jsonDetail["Longitude"].stringValue
var fac = jsonDetail["Faculty"].stringValue
var location = jsonDetail["Location"].stringValue
var external = jsonDetail["ExternalLink"].stringValue
var title = jsonDetail["Title"].stringValue
var highlight = jsonDetail["Highlight"].stringValue
row.append(jsonDetail["FacultyName"].stringValue)//0
row.append(jsonDetail["คณะ"].stringValue)//1
row.append(fac)//2
row.append(title)//3
row.append(location)//4
row.append(highlight)//5
row.append(artPic)//6
row.append(lat)//7
row.append(long)//8
row.append(external)//9
arrDetail.append(row)
}
return arrDetail
}
func loadJSONFile(){
if let path = NSBundle.mainBundle().pathForResource(HIGHLIGHT_JSON_FILE, ofType: "json"){
do {
let data = try NSData(contentsOfURL: NSURL(fileURLWithPath: path), options: NSDataReadingOptions.DataReadingMappedIfSafe)
loadJSON(data);
} catch let error as NSError {
print(error.localizedDescription)
}
} else {
print("Invaild filename/path!")
}
}
func loadJSON(data: NSData) {
jsonObj = JSON(data: data)
if jsonObj != JSON.null {
print("jsonData:\(jsonObj)")
} else {
print("invalid JSON file")
}
}
}