Home > database >  Parse html tag from json response in kotlin
Parse html tag from json response in kotlin

Time:01-19

Hey I am working in json response with html tag in kotlin. I don't understand how to parse html tag in response. I tried to work with enter image description here

Is it possible in android we can do?

CodePudding user response:

You can render those html codes into a text view, try to use this library to do that. https://github.com/SysdataSpA/SDHtmlTextView

Edit: You can also use WebView to render html.

CodePudding user response:

Once retrieved the JSON object you could try to import Jsoup to parse the html contained in the "title" key and query the value:

    dependencies {
        implementation 'org.jsoup:jsoup:1.14.1'
    }
    val jsonArray = JSONArray(result)
    val jsonObject: JSONObject = jsonArray.getJSONObject(0)
    val titleHtml = jsonObject.get("title")
    val parsedHTML = Jsoup.parse(titleHtml)
    val title = parsedHTML.select("h1[id=sample-markdown]").attr("content")
  •  Tags:  
  • Related