drd43058 2016-11-29 04:16
浏览 57

在Objective C中从URL下载JSON的简单方法

I am using a php file to connect to a MYSQL database and return a table from the database in a JSON format.

Here is the link to the PHP file which displays the JSON result: http://tradersdb.rf.gd/service1.php

I have tried many variations of objective C code to download this JSON formatted information into an objective C array but have had no success. I am hoping for this code to be used in an IOS application that will read from the MYSQL database.

I feel as though the issue however, is with the PHP file and potential incorrect JSON formatting rather than any of the Objective C code. I have used json_encode() in the PHP file. All help is appreciated.

  • 写回答

1条回答 默认 最新

  • dqx24298 2016-11-29 05:01
    关注

    After doing some tests on the JSON link you provided, turns out your web server does inject HTML in front of the actual content. This HTML is meant to set a cookie via JavaScript and then automatically load the actual data.

    The problem is not with your JSON, but your web framework. You'll see below that the page loads aes.js from your root directory, which is most likely used for the decryption/encryption of the cookie.

    Here is the HTML returned:

    <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("db90ed280d6dd97b2c5a2f1352115adf");
            document.cookie = "__test=" + toHex(slowAES.decrypt(c, 2, a, b)) + "; expires=Thu, 31-Dec-37 23:55:55 GMT; path=/";
            location.href = "http://tradersdb.rf.gd/service1.php?i=1";
        </script>
        <noscript>
            This site requires Javascript to work, please enable Javascript in your browser or use a browser with Javascript support
        </noscript>
    </body>
    </html>
    

    It's most likely a bot protection plugin on your server. If you have control over your server plugins, you should disable / remove it. The only other options are to either find a better host which allows plain content access or find a way to disable this server setting.

    Update:

    It would appear this is a free hosting server. I would strongly suggest you move off this and you will find that your code works. If it's a free host, you probably can't disable it. In that case, this host provider is useless for you and you should search for a new one.

    评论

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。