Skip to content

Instantly share code, notes, and snippets.

@venj
Last active August 29, 2015 14:04
Show Gist options
  • Save venj/d9eb0ff9219bcfe00a01 to your computer and use it in GitHub Desktop.
Save venj/d9eb0ff9219bcfe00a01 to your computer and use it in GitHub Desktop.
#!/usr/bin/env xcrun swift
import Foundation
if NSFoundationVersionNumber < 1139.1 {
println("You need Xcode6-DP5 and up to run this script")
exit(1)
}
let args = Process.arguments
if args.count != 2 {
println("Please specify *one* path argument.")
exit(1)
}
let json_path = args[1]
var fm = NSFileManager.defaultManager()
if fm.fileExistsAtPath(json_path) {
let data = NSData(contentsOfFile:json_path)
var error:NSError?
let json:AnyObject! = NSJSONSerialization.JSONObjectWithData(data, options:nil, error:&error)
if let e = error {
println("Error parsing JSON: \(e.localizedDescription)")
}
else {
let dict = json as? NSDictionary
if dict != nil {
println("JSON is a dictionary:")
println("\(dict)")
}
let arr = json as? NSArray
if arr != nil {
println("JSON is an array:")
println("\(arr)")
}
}
}
else {
println("File not found:\(json_path)")
}
@zhuangya
Copy link

zhuangya commented Aug 5, 2014

竟然可以写 hashbang !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment