-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJSONParser.swift
52 lines (40 loc) · 1.99 KB
/
JSONParser.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
//
// JSONParser.swift
//
// Created by Cristian Cardoso on 5/3/17.
// Copyright © 2017 Cristian Cardoso. All rights reserved.
//
import Foundation
class JSONParser : NSObject {
private static var _mInstance : JSONParser? = nil
public static func getInstance() -> JSONParser{
if (_mInstance == nil){
_mInstance = JSONParser()
}
return _mInstance!
}
func parseCampus(JSONData: [NSDictionary]) -> [Campus] {
var campusArr : [Campus] = []
for item in JSONData {
var lat : Double = 0.0
var lng : Double = 0.0
let id = item[JSON_KEYS.CAMPUSES.JSON_KEY_ID] as? String
let instituteId = item[JSON_KEYS.CAMPUSES.JSON_KEY_INSTITUEID] as? String
if let location = item[JSON_KEYS.CAMPUSES.JSON_KEY_LOCATION] as? [String : AnyObject]{
lat = location[JSON_KEYS.CAMPUSES.JSON_KEY_LAT] as! Double
lng = location[JSON_KEYS.CAMPUSES.JSON_KEY_LNG] as! Double
}
let map = item[JSON_KEYS.CAMPUSES.JSON_KEY_MAP] as? String
let name = item[JSON_KEYS.CAMPUSES.JSON_KEY_NAME] as? String
let website = item[JSON_KEYS.CAMPUSES.JSON_KEY_WEBSITE] as? String
let description = item[JSON_KEYS.CAMPUSES.JSON_KEY_DESCRIPTION] as? String
let tour360 = item[JSON_KEYS.CAMPUSES.JSON_KEY_TOUR_360] as? String
let image = item[JSON_KEYS.CAMPUSES.JSON_KEY_IMAGE] as? String
let location = Location(lat: lat, lng: lng)
let description_image = item[JSON_KEYS.CAMPUSES.JSON_KEY_DESCRIPTION_IMAGE] as? String
let campus = Campus(id: id, instituteId: instituteId, location: location, mapImage: map, name: name, website: website, tour360 : tour360, description: description, image : image, description_image: description_image)
campusArr.append(campus)
}
return campusArr
}
}