Kushal Sharma
Kushal Sharma

Reputation: 97

How to remove tags/ special letters while fetching data from Json to an android app?

I am getting the JSON responses like this ->

Here you can check out the complete JSON response -> https://api.nasa.gov/techtransfer/patent/?engine&api_key=DEMO_KEY

Also this is my data class look like ->

          @Parcelize
             data class Patent(
             val count: Int,
             val page: Int,
             val perpage: Int,
             val results: List<List<String>>,
             val total: Int
                 ) : Parcelable

I parsed data using Retrofit.

Here's the interface->

    interface NasaInterface {

@GET("techtransfer/patent/?telescope&api_key=${API_KEY}")
fun getNasaPatents(): Call<Patent>   }
              
     
        object NasaService {
     
         val nasaInterface: NasaInterface

         init {
         val retrofit = Retrofit.Builder()
                  .baseUrl(BASE_URL)
                  .addConverterFactory(GsonConverterFactory.create())
                  .build()

    nasaInterface = retrofit.create(NasaInterface::class.java)
}   }

And here's the function of getting the data ->

                private fun callingAdapter() {
    val nasaPatents = NasaService.nasaInterface.getNasaPatents()

    nasaPatents.enqueue(object : Callback<Patent>, iPostAdapter {
        override fun onResponse(call: Call<Patent>, response: Response<Patent>) {
            val nasaPatentsi = response.body()

            if (nasaPatentsi != null) {

                adapter = PatentAdapter(this@MainFragment, nasaPatentsi, this)
                recyclerViewItems!!.adapter = adapter
            }

        }

        override fun onFailure(call: Call<Patent>, t: Throwable) {
            Log.d("pERROR", "$t , $call")
            progressLoaderAdp!!.visibility = View.VISIBLE

        }

I want to remove those tags like "span class..." . When you look at that JSON response, you will see that all important stuff coming in app from Result Key. I wonder if we can remove those tags from values of Result key?

Upvotes: 1

Views: 163

Answers (1)

Grela
Grela

Reputation: 106

Instead of removing the HTML code, I would go for setting the text as HTML.

Html.fromHtml("NASA TEXT WITH HTML", flag)

Upvotes: 1

Related Questions