json parser in swift
//: Playground - noun: a place where people can play
import Cocoa
//gets a JSON string from a url via a get request
func getJSON(address:String) -> String? {
if let url = URL(string: address) {
do {
let contents = try String(contentsOf: url)
return contents
} catch {
return nil
}
} else {
return nil
}
}
//main JSON enum wrapper for Avocado parser
enum JSON {
case number(Int)
case string(String)
case boolean(Bool)
indirect case array([JSON])
indirect case object([String:JSON])
case null
}
let intset:Set<Character> = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]
enum pSetting {
case arr
case obj
}
func parseJSON(input:String, mode:pSetting) -> JSON {
var start = input.startIndex
var end = input.endIndex
switch mode {
case .arr: break
case .obj: break
}
return JSON.null
}
let a = "hello world"
let b = a.startIndex
let c = a.index(after: b)
let d = a.substring(to: c)