ios - 无法用 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 附近没有字符”问题。
解决方案
找到它。由于响应是 HTML,我使用 swiftSoup 来解析和使用它。谢谢大家,我没有注意到我没有得到 JSON 对象作为响应。
推荐阅读
- scala - 如何避免在具有继承行为的 Akka Actor 中改变状态变量?
- google-bigquery - BigQuery:派生字段的名称无法识别
- yii - yii 1.1.16 应用需要 VPS 而不是共享主机,是这样吗?
- android-studio - Gradle - 如果模块声明时没有路径和配置,则同步不起作用
- java - 这种结构有意义吗?
- flutter - 如何从搜索栏中保存搜索到的项目并在颤动中显示来自sharedprefernce的保存列表
- search - 如何在 Prolog 中为“10 只猫中有 8 只倒计时”数字游戏求解器生成不同的解决方案?
- angular - Angular 材质表按所有列过滤
- tensorflow - 如何提高卷积神经网络中 GPU 的使用率?
- ruby - 自 Catalina 更新以来的部署错误 - zsh: /usr/local/bin/cap: bad interpreter... no such file or directory