首页 > 解决方案 > 无法用 Alamofire 和 swift 解析

问题描述

我正在尝试模拟此 java 代码:

try {
        Connection.Response programacion1 = Jsoup.connect(URLProg1)
                .cookies(cookies)  
                .data(formData2)  
                .method(Connection.Method.POST)  
                .userAgent(USER_AGENT)  
                .execute();


        Document programacion= programacion1.parse();

        Elements table = programacion.select("table").tagName("datos"); //select the table.

        Elements rows = table.select("tr");


        FileWriter programacionTexto = null;
        PrintWriter pw1 = null;

使用 AlamoFire 5 使用这个 Alamofire swift 代码:

AF.request(URLProg1, method: .post, parameters: parametersProgramcion, encoding: URLEncoding.httpBody).responseString
                                { (response3) in
                                    let value = response3.value
                                    let json = JSON(response3.value)
                                    let table = json["datos"]
                                    let rows = table["tr"]
                                    }

女巫我不知道它是否对最终目标正确。不过,这是我运行应用程序时的主要问题,我可以调试打印(在需要时)HTML 输出,但响应请求带来 nil(见图),所以 json 也是 0 等等,因此,我无法使用数据。就像它不解析或类似的东西。你能帮我解决这个问题吗?

顺便说一句,我也确实使用了 responseJSON,但我也看到了同样的问题,即“0 附近没有字符”问题。

在此处输入图像描述这是调试状态

标签: iosswiftxcodeparsingalamofire

解决方案


找到它。由于响应是 HTML,我使用 swiftSoup 来解析和使用它。谢谢大家,我没有注意到我没有得到 JSON 对象作为响应。


推荐阅读