skip to Main Content

This is the response i got. I want to extract the <span> tag from price_html

        "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>",```

2

Answers


  1. just reference the object

    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']);
    Login or Signup to reply.
  2. If you have it as a string you can use

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

    which will return the index of the first char in the search string. Then you add the length of the search string to that index and save to index. Then you can do string.indexOf("</", index) to get the end of the content. And with string.subString(indexStart, indexEnd) you get the content.

    Edit: If you can’t get it to work with that take a look at the org.json package which is really useful when working with java and json.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search