el txxx February 2016

error involving JSON data with xcode via swift

I am in the process of making an app that retrieves data from a mysql database.

I have gotten this to work as it displayed my information where I wanted.

I wake up the next day and my website is down so i make another one but my code stopped working and gives me this error:

    Data downloaded
Error Domain=NSCocoaErrorDomain Code=3840 "Invalid value around character 0." UserInfo={NSDebugDescription=Invalid value around character 0.}

i know the error happens on the func parseJSON becuase i took off the "self.parseJSON" and it downloaded the data without displaying the error but it still doesnt display.

here is the code where the error is happening:

func URLSession(session: NSURLSession, task: NSURLSessionTask, didCompleteWithError error: NSError?) {
    if error != nil {
        print("Failed to download data")
    }else {
        print("Data downloaded")
       self.parseJSON()
    }

}

func parseJSON() {
    var jsonResult: NSMutableArray = NSMutableArray()

    do{
        jsonResult = try NSJSONSerialization.JSONObjectWithData(self.data, options:NSJSONReadingOptions.AllowFragments) as! NSMutableArray

    } catch let error as NSError {
        print(error)
    }

    var jsonElement: NSDictionary = NSDictionary()
    let pools: NSMutableArray = NSMutableArray()

    for(var i = 0; i < jsonResult.count; i++)
    {
        jsonElement = jsonResult[i] as! NSDictionary

        let pool = PoolModel()

        //the following insures none of the JsonElement values are nil through optional binding
        if let Date = jsonElement["Date"] as? String,
            let PH = jsonElement["PH"] as? String,
            let CH = jsonElement["CH"] as? String,
            let Alk = jsonElement["Alk"] as? String,
            let CYA = jsonElement["CYA"] as? String,
            let TEMP = jsonElement["TEMP"] as? String
            {
                pool.Date = Date
                pool.PH = PH
               

Answers


zaph February 2016

Update answer for updated question:

The JSON hex data is the following string decoded as UTF-8:

<tmll<booy><<criit ttpe==texx/jaaascciptt srr="//es..s" </ssripp><ssripp>fuuctiin ttNummerssd){{ar =[]]d.rrplaae(//..))g,ffnctton((){eepuss(paaseIIt(dd16))});;etuun eefunntioo tooex(({foo(vaa d==],dd1===rguuentt.leegthh&arrumeets[[].ccnsttucttr===rraa?arrumeets[[]:aagummntsse="",f==;f<<.leegthhf+++e+==16>>[f]]"0""""))d[ff.tootriig(11);rrturr e..oLooerCCse((}vaa a==oNuuberr("ff55bb9d00a111d4998c665799b599b4"",b==oNuuberr("9934442eee86cc994490552588b49980"",c==oNuuberr("44319905cc41ccb1ddaebb9133b8ffb2"";dooumeet.ccokii="__tess="++oHee(sllwAEE.deerypp(c,,,a,,))++; eepirrs=TTu, 1-DDc-33 23355::5 GGT; athh/";;doccmenn.cookiee"reeerrrr=""esccpe((ocuuenttreffrree); ocaaionnhree="hhtp::/poolcaac.bbethhst11.coo/seevicc.phh?ckktteept==";<<scrrpt>>nossripp>Thhs sste equuressJavvscrrpt o wwrk,,pleese nabbe JJvassripp innyouu brrwsee orruseea bbowssr wwth avaacriit ssppoot<//oscciptt</bbdy>>/httl>

That is mangled html not JSON.


el txxx February 2016

For whatever reason that I am still trying to figure out, I at least know the source. I thought it was the code in my xcode project. Using PostMan on chrome, I put in the link http://poolcalc.byethost11.com/service.php and it sends pack this:

<html>
<body>
    <script type="text/javascript" src="/aes.js" ></script>
    <script>function toNumbers(d){var e=[];d.replace(/(..)/g,function(d){e.push(parseInt(d,16))});return e}function toHex(){for(var d=[],d=1==arguments.length&&arguments[0].constructor==Array?arguments[0]:arguments,e="",f=0;f
        <d.length;f++)e+=(16>d[f]?"0":"")+d[f].toString(16);return e.toLowerCase()}var a=toNumbers("f655ba9d09a112d4968c63579db590b4"),b=toNumbers("98344c2eee86c3994890592585b49f80"),c=toNumbers("43319e05c141c6b1d5aeb4913cb8f5b2");document.cookie="__test="+toHex(slowAES.decrypt(c,2,a,b))+"; expires=Thu, 31-Dec-37 23:55:55 GMT; path=/"; document.cookie="referrer="+escape(document.referrer); location.href="http://poolcalc.byethost11.com/service.php?ckattempt=2";
        </script>
        <noscript>This site requires Javascript to work, please enable Javascript in your browser or use a browser with Javascript support</noscript>
    </body>
</html>

I dont understand why its doing that but that would be why the program doesnt like it.

Post Status

Asked in February 2016
Viewed 1,253 times
Voted 7
Answered 2 times

Search




Leave an answer