我想从收到的 JSON 响应中提取 <span> 标签的内容。怎么做?

I want to extract the content of <span> tag from this received JSON Response. How to do that?

这是我得到的回复。我想从 price_html

中提取 <span> 标签
        "id": 2320,
        "name": "Lakme Sun Expert Sunscreen (spf-50) 50ml",
        "slug": "lakme-sun-expert-sunscreen-spf-50-50ml",
        "permalink": "https://www.utkalmerchandise.com/product/lakme-sun-expert-sunscreen-spf-50-50ml/",
        "date_created": "2020-08-01T05:49:57",
        "date_created_gmt": "2020-08-01T05:49:57",
        "date_modified": "2020-08-01T05:49:57",
        "date_modified_gmt": "2020-08-01T05:49:57",
        "type": "variable",
        "status": "publish",
        "featured": false,
        "catalog_visibility": "visible",
        "description": "",
        "short_description": "",
        "sku": "",
        "price": "95",
        "regular_price": "",
        "sale_price": "",
        "date_on_sale_from": null,
        "date_on_sale_from_gmt": null,
        "date_on_sale_to": null,
        "date_on_sale_to_gmt": null,
        "price_html": "<span class=\"woocommerce-Price-amount amount\"><span class=\"woocommerce-Price-currencySymbol\">&#8377;</span>95.00</span> &ndash; <span class=\"woocommerce-Price-amount amount\"><span class=\"woocommerce-Price-currencySymbol\">&#8377;</span>219.00</span>",```

仅引用对象

var myObj={"id": 2320,
        "name": "Lakme Sun Expert Sunscreen (spf-50) 50ml",
        "slug": "lakme-sun-expert-sunscreen-spf-50-50ml",
        "permalink": "https://www.utkalmerchandise.com/product/lakme-sun-expert-sunscreen-spf-50-50ml/",
        "date_created": "2020-08-01T05:49:57",
        "date_created_gmt": "2020-08-01T05:49:57",
        "date_modified": "2020-08-01T05:49:57",
        "date_modified_gmt": "2020-08-01T05:49:57",
        "type": "variable",
        "status": "publish",
        "featured": false,
        "catalog_visibility": "visible",
        "description": "",
        "short_description": "",
        "sku": "",
        "price": "95",
        "regular_price": "",
        "sale_price": "",
        "date_on_sale_from": null,
        "date_on_sale_from_gmt": null,
        "date_on_sale_to": null,
        "date_on_sale_to_gmt": null,
        "price_html": "<span class=\"woocommerce-Price-amount amount\"><span class=\"woocommerce-Price-currencySymbol\">&#8377;</span>95.00</span> &ndash; <span class=\"woocommerce-Price-amount amount\"><span class=\"woocommerce-Price-currencySymbol\">&#8377;</span>219.00</span>"};
        
        console.log(myObj['price_html']);

如果你有它作为一个字符串你可以使用

string.indexOf("<span class="...">")

这将 return 搜索字符串中第一个字符的索引。然后将搜索字符串的长度添加到该索引并保存到 index。然后你可以做string.indexOf("</", index)得到内容的结尾。使用 string.subString(indexStart, indexEnd) 您可以获得内容。

编辑: 如果你无法使用它,请查看 org.json 包在使用 java 和 json.

时非常有用