【问题标题】:I want to get list of top 250 movies of imdb but I'm unable as it give me "{}" not whole list我想获得 imdb 的前 250 部电影的列表,但我不能,因为它给了我“{}”而不是整个列表
【发布时间】:2018-05-21 08:47:25
【问题描述】:

我已正确添加库,没有任何错误,但未显示所需的结果。我得到了返回类型字符串并将其保存到一个变量中,然后将其设置为文本视图。我已经卡在这里了。请帮帮我。

public String TableToJson() throws JSONException {
    int i=0;

    String s="http://www.imdb.com/chart/top";
    Document doc = Jsoup.parse(s);
    JSONObject jsonParentObject = new JSONObject();
    //JSONArray list = new JSONArray();
    for (Element table : doc.select("table")) {
        for (Element row : table.select("tr")) {
            JSONObject jsonObject = new JSONObject();

            Elements tds = row.select("td");
            i++;
            String no = Integer.toString(i);
            String Name = tds.get(1).text();
            String rating = tds.get(2).text();

            jsonObject.put("Ranking", no);
            jsonObject.put("Title", Name);
            jsonObject.put("Rating", rating);

            jsonParentObject.put(Name, jsonObject);
        }
    }
    return jsonParentObject.toString();
}

输出只有

{}

【问题讨论】:

  • 调试器派上用场的时候就是这样
  • 你不认为你需要先解析 <tbody> 再解析 <tr> 吗? @公主的王子
  • 也试过了,但同样的问题...@AkshayMahajan
  • 您要准确解析什么 JSON?那只是一个 HTML 网页。

标签: java android


【解决方案1】:

如您所见,仅使用正则表达式即可。

示例查询可能与此类似

<strong title=".*</strong>

显示 250 个匹配项Tested using freeformatter

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-10-21
    • 2018-10-29
    • 2019-10-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-15
    相关资源
    最近更新 更多