I have a PHP file that queries a database and echos the following results [{"longitude":"-73.0247","latitude":"40.8066"}]
. In my Xcode project, I am trying to figure out how to use JSON to parse the data and I am having bugs with my current code.
class coordinates {
var longitude: String?
var latitude: String?
}
override func viewDidLoad() {
super.viewDidLoad()
do {
let data = try(NSData(contentsOfURL: NSURL(string: "http://thisiscensored.net/get.php")!, options: NSDataReadingOptions.DataReadingMappedIfSafe))
let jsonDictionary = try(NSJSONSerialization.JSONObjectWithData(data, options: .MutableContainers))
print(jsonDictionary)
} catch let err {
print(err)
}
When I build and run, I get the following error - Error Domain=NSCocoaErrorDomain Code=3840 "Garbage at end." UserInfo={NSDebugDescription=Garbage at end.
Update - cURL Terminal Output
[{"longitude":"-73.0247","latitude":"40.8068"}]
<!-- Hosting24 Analytics Code -->
<script type="text/javascript" src="http://stats.hosting24.com/count.php"></script>
<!-- End Of Analytics Code -->