-2

i am using alamofire to call api. but in this particular api i am getting nil value as a response. actually when i hit my api in my browser its working pretty well.

here is my code

 func web()
{


    request(.GET, "http://www.horecasupply.nl/AJAX?function=appStructure", parameters: nil, encoding: .JSON).responseJSON { (response : Response<AnyObject, NSError>) -> Void in
        if response.result.value != nil {
            print(response.result.value)
        }

    }

}

getting nil value and when i print respose its showing me

Printing description of response.result.Failure:
Error Domain=NSCocoaErrorDomain Code=3840 "Invalid value around character 1."         
UserInfo={NSDebugDescription=Invalid value around character 1.}

EDIT 1:: tried responsestring instead of responsejson. but getting different kind of response so how can i convert it?

\r\n\r\n\r\n\r\n</script>\r\n DD_belatedPNG.fix(\'img, .png_bg\'); //fix any or .png_bg background-images </script>\r\n\r\n\r\n</script>\r\n</script>-->\r\n\r\n\r\n\r\n\r\n\r\n \r\n\r\n")

Govind Rakholiya
  • 295
  • 1
  • 3
  • 20
  • Try using `responseString` instead of `responseJson` [Alamofire invalid value around character 0](http://stackoverflow.com/questions/32355850/alamofire-invalid-value-around-character-0) – Bista Jan 11 '16 at 09:13
  • by using responsestring getting this kind of response \r\n\r\n\r\n\r\n\r\n DD_belatedPNG.fix(\'img, .png_bg\'); //fix any or .png_bg background-images \r\n\r\n\r\n\r\n-->\r\n\r\n\r\n\r\n\r\n\r\n \r\n\r\n") – Govind Rakholiya Jan 11 '16 at 09:41
  • I ran the same code u have posted & it works properly .I m getting same response as of browser. – poojathorat Jan 11 '16 at 09:49
  • which xcode are you using ? poojathorat – Govind Rakholiya Jan 11 '16 at 09:54
  • 2
    Your code snippet works for me ([screenshot](https://www.evernote.com/l/AOwYaIzaSFZEebo3JmdJu5zWCCXIMc_GUPE)). – Eric Aya Jan 11 '16 at 09:57
  • have you changed anything in your info.plist?? @EricD. – Govind Rakholiya Jan 11 '16 at 10:11
  • Just added ["Allow arbitrary loads"](https://www.evernote.com/l/AOzc6LuWYLtE4ZcShiuwIJxzJe9FsQdRpxI) but nothing special other than that. – Eric Aya Jan 11 '16 at 10:13
  • its really annoying same code not working for me. in response after getting data in number format i am getting this. result : FAILURE: Error Domain=NSCocoaErrorDomain Code=3840 "Invalid value around character 1." UserInfo={NSDebugDescription=Invalid value around character 1. – Govind Rakholiya Jan 11 '16 at 10:20
  • hi @EricD. is there any other solution? – Govind Rakholiya Jan 11 '16 at 10:21

1 Answers1

-2

Give this code a shot, this should work:

    Alamofire.request(.GET, "http://www.horecasupply.nl/AJAX?function=appStructure").responseJSON { response in
    if response.result.value != nil {
        print(response.result.value)
    }
}
Stefan DeClerck
  • 1,162
  • 2
  • 12
  • 22
  • 1
    Why? How? OP's code worked for me, why do you think replacing it by yours would improve their situation? Please explain your answer. – Eric Aya Jan 11 '16 at 13:21