Last active
August 29, 2015 14:04
-
-
Save venj/d9eb0ff9219bcfe00a01 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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)") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
竟然可以写 hashbang !