如何在android中使用jsoup从html获取脚本

如何在android中使用jsoup从html获取脚本,android,jsoup,Android,Jsoup,我想使用jsoup从html中的以下脚本标记中获取“慢炖食谱的褐色砂锅杂烩”和“PT20M”。我看了一眼,但没有找到明确的解决办法。感谢您的指导 <script id="ld" type="application/ld+json">{"@context": "http://schema.org/","@type": "Recipe","name": "Hash Brown Casserole for the Slow Cooker Recipe","prepTime":"PT20M"

我想使用jsoup从html中的以下脚本标记中获取“慢炖食谱的褐色砂锅杂烩”和“PT20M”。我看了一眼,但没有找到明确的解决办法。感谢您的指导

<script id="ld" type="application/ld+json">{"@context": "http://schema.org/","@type": "Recipe","name": "Hash Brown Casserole for the Slow Cooker Recipe","prepTime":"PT20M"</script>
{@context”:http://schema.org/“,“@type”:“菜谱”,“名称”:“慢炖菜谱用褐色砂锅”,“prepTime”:“PT20M”

查看脚本中有id。您可以按id获取元素,并且有一个子元素。然后您可以将该子元素转换为json对象。以下是示例:

Document doc = Jsoup.parse("<script id=\"ld\" type=\"application/ld+json\">{\"@context\": \"http://schema.org/\",\"@type\": \"Recipe\",\"name\": \"Hash Brown Casserole for the Slow Cooker Recipe\",\"prepTime\":\"PT20M\"}</script>");
        String str = doc.getElementById("ld").childNodes().get(0).toString();
        JSONObject jsonObject = new JSONObject(str);
        System.out.println(jsonObject.getString("name"));
        System.out.println(jsonObject.getString("prepTime"));

这里有人吗?!
String str = doc.getElementById("ld").childNodes().get(0).toString()+"}";