0

I am trying to parse JSON data from a website (http://dropdelivery.vacau.com/). I am using alamofire to try and access the data

    let url = "http://dropdelivery.vacau.com/"
    Alamofire.request(.GET, url).responseJSON {
        response in
        if response.result.isSuccess {
            let jsonDic = response.result.value as! NSDictionary
            let responseData = jsonDic["responseData"] as! NSDictionary
            print(responseData)

when I run this it returns nothing what am I doing wrong? Is there better way to approach the problem.

1
  • 1
    Your query produces no json but html page as stated in the answer below from Andy. You need another service url that have only json in response or you need take json from it html page that is between the tags <body> ... </ body> befor let jsonDic = response.result.value as! NSDictionary and in this case it will be no responseJSON type of request. For further work with the json have a great library: github.com/SwiftyJSON/SwiftyJSON Commented Oct 18, 2015 at 8:09

1 Answer 1

1

One problem is that you don't have valid JSON at that URL; it's wrapped by HTML so Alamofire cannot parse it.

If you take a look at the source of the URL you mentioned, you see this:

<html>
<head>
<title>Current Item</title>
</head>

<body> 

{"item":{"title":"Sorry were closed","price":null,"image":null}}      
</body>
</html>

<!-- Hosting24 Analytics Code -->
<script type="text/javascript"  src="http://stats.hosting24.com/count.php"></script>
<!-- End Of Analytics Code -->

To get it working, you need to only see this:

{"item":{"title":"Sorry were closed","price":null,"image":null}}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.