title: RestAPI JSON Parsing
body: <pre><code>            i am new to android. i was search many question,pages,website for my topic. 
              i am trying to parse **RestAPI** like below but i am getting only value which return into below api not exact value from the server.
              please anybody help to how to get exact value from this api. 
              i am new to android. i was search many question,pages,website for my topic. 
              i am trying to parse **RestAPI** like below but i am getting only value which return into below api not exact value from the server.
              please anybody help to how to get exact value from this api. 
                  
                          {
                        &quot;name&quot;: &quot;JSONWebAPI&quot;,
                        &quot;description&quot;: &quot;JSON API for android appliation&quot;,
                        &quot;url&quot;: &quot;http://SG2NWVPWEB022/Services/LoginHandler.ashx&quot;,
                        &quot;interfaces&quot;: [
                          {
                            &quot;name&quot;: &quot;RestAPI&quot;,
                            &quot;methods&quot;: [
                              {
                                &quot;name&quot;: &quot;getProject&quot;,
                                &quot;parameters&quot;: [
                                  {
                                    &quot;name&quot;: &quot;projectid&quot;,
                                    &quot;type&quot;: &quot;int32&quot;
                                  }
                                ],
                                &quot;returnvalue&quot;: &quot;object&quot;
                              },
                              {
                                &quot;name&quot;: &quot;getNews&quot;,
                                &quot;parameters&quot;: [
                                  
                                ],
                                &quot;returnvalue&quot;: &quot;object&quot;
                              },
                              {
                                &quot;name&quot;: &quot;getAllDownloads&quot;,
                                &quot;parameters&quot;: [
                                  
                                ],
                                &quot;returnvalue&quot;: &quot;object&quot;
                              },
                              {
                                &quot;name&quot;: &quot;getvideo&quot;,
                                &quot;parameters&quot;: [
                                  
                                ],
                                &quot;returnvalue&quot;: &quot;object&quot;
                              },
                            
                                  {
                                    &quot;name&quot;: &quot;type&quot;,
                                    &quot;type&quot;: &quot;int32&quot;
                                  },
                                  {
                                    &quot;name&quot;: &quot;requirement&quot;,
                                    &quot;type&quot;: &quot;int32&quot;
                                  }
                                ],
                                &quot;returnvalue&quot;: &quot;object&quot;
                              },
                              {
                                &quot;name&quot;: &quot;getBrochure&quot;,
                                &quot;parameters&quot;: [
                                  {
                                    &quot;name&quot;: &quot;projectid&quot;,
                                    &quot;type&quot;: &quot;int32&quot;
                                  }
                                ],
                                &quot;returnvalue&quot;: &quot;object&quot;
                              },
                              {
                                &quot;name&quot;: &quot;getGallery&quot;,
                                &quot;parameters&quot;: [
                                  {
                                    &quot;name&quot;: &quot;projectid&quot;,
                                    &quot;type&quot;: &quot;int32&quot;
                                  }
                                ],
                                &quot;returnvalue&quot;: &quot;object&quot;
                              },
                              {
                                &quot;name&quot;: &quot;getWork&quot;,
                                &quot;parameters&quot;: [
                                  {
                                    &quot;name&quot;: &quot;projectid&quot;,
                                    &quot;type&quot;: &quot;int32&quot;
                                  }
                                ],
                                &quot;returnvalue&quot;: &quot;object&quot;
                              },
                              {
                                &quot;name&quot;: &quot;getPlan&quot;,
                                &quot;parameters&quot;: [
                                  {
                                    &quot;name&quot;: &quot;projectid&quot;,
                                    &quot;type&quot;: &quot;int32&quot;
                                  }
                                ],
                                &quot;returnvalue&quot;: &quot;object&quot;
                              },
                              {
                                &quot;name&quot;: &quot;getfacility&quot;,
                                &quot;parameters&quot;: [
                                  {
                                    &quot;name&quot;: &quot;projectid&quot;,
                                    &quot;type&quot;: &quot;int32&quot;
                                  }
                                ],
                                &quot;returnvalue&quot;: &quot;object&quot;
                              }
                            ]
                          }
                        ]
                      }
         //baseactvity
  </code></pre>
  <p>open class BaseActivity : AppCompatActivity(), CoroutineScope {
  override val coroutineContext: CoroutineContext
  get() = Dispatchers.Main + mJob</p>
  <pre><code>                        val mJob = Job()
                  
                          lateinit var apiService: ApiService
                          lateinit var huntRepository: HuntRepository
                          lateinit var huntViewModel: HuntViewModel
                  
                      override fun onCreate(savedInstanceState: Bundle?) {
                          super.onCreate(savedInstanceState)
                  
                          apiService = ApiClient.createService(this)
                          huntRepository = HuntRepository(apiService)
                          huntViewModel = HuntViewModel(huntRepository)
                      }
                      override fun onDestroy() {
                          super.onDestroy()
                          mJob.cancel()
                      }
                  }
  </code></pre>
  <p>open class BaseActivity : AppCompatActivity(), CoroutineScope {
  override val coroutineContext: CoroutineContext
  get() = Dispatchers.Main + mJob</p>
  <pre><code>                        val mJob = Job()
                  
                          lateinit var apiService: ApiService
                          lateinit var huntRepository: HuntRepository
                          lateinit var huntViewModel: HuntViewModel
                  
                      override fun onCreate(savedInstanceState: Bundle?) {
                          super.onCreate(savedInstanceState)
                  
                          apiService = ApiClient.createService(this)
                          huntRepository = HuntRepository(apiService)
                          huntViewModel = HuntViewModel(huntRepository)
                      }
                      override fun onDestroy() {
                          super.onDestroy()
                          mJob.cancel()
                      }
                  }
      
              
  //BaseRepository explanining base for android
     
  
              open class BaseRepository {
                  suspend fun &lt;T : Any&gt; safeApiCall(call: suspend () -&gt; Response&lt;T&gt;): Result&lt;T&gt;? {
                      try {
                          val response = call.invoke()
                          if (response.isSuccessful) {
                              val body = response.body()
                              if (body != null) return Result.Success(body)
                          }
                          return error(&quot; ${response.code()} ${response.message()}&quot;)
                      } catch (e: Exception) {
                          return error(e.message ?: e.toString())
                      }
                  }
              
                  private fun &lt;T : Any&gt; error(message: String): Result&lt;T&gt; {
                      Log.e(&quot;API Error :&quot;, &quot;===&gt; $message&quot;)
                      return Result.Error(&quot;Network call has failed for a following reason: $message&quot;)
                  }
              }
  
               
  //apprepo
     
  
                  class HuntRepository(val api: ApiService) : BaseRepository() {
              
                  suspend fun getLogin(body: HashMap&lt;String, String&gt;): Result&lt;LoginData&gt;? {
                      return safeApiCall(
                          call = { api.callLoginAsync(body).await() }
                      )
                  }
      
      interface ApiService {
          @POST(&quot;Login&quot;)
          fun callLoginAsync(@Body body: HashMap&lt;String, String&gt;): Deferred&lt;Response&lt;LoginData&gt;&gt;
      
  //result
  
          sealed class Result&lt;out T: Any&gt; {
              data class Success&lt;out T : Any&gt;(val data: T) : Result&lt;T&gt;()
              data class Error(val exception: String) : Result&lt;Nothing&gt;()
          }
  
        
         
  //api
  
      object ApiClient {
      
          fun createService(context: Context): ApiService {
              return setupRetrofit(context)
                  .create(ApiService::class.java)
          }
      
          fun setupOkHttp(context: Context): OkHttpClient {
      
              val cacheSize = 10 * 1024 * 1024 // 10 MiB
              val cacheDir = File(context.cacheDir, &quot;HttpCache&quot;)
              val cache = Cache(cacheDir, cacheSize.toLong())
              //TODO Replace sample_certificate.pem with your server public certificate in raw resource and uncomment .setupNetworkSecurity(context)
              val builder = OkHttpClient.Builder()
                  .readTimeout(20, TimeUnit.SECONDS)
                  .connectTimeout(20, TimeUnit.SECONDS)
      //            .setupNetworkSecurity(context)
                  .cache(cache)
              // if (BuildConfig.DEBUG) {
              val loggingInterceptor = HttpLoggingInterceptor()
              loggingInterceptor.level = HttpLoggingInterceptor.Level.BODY
              builder.addInterceptor(loggingInterceptor)
              builder.addInterceptor { chain -&gt;
                  val original = chain.request()
                  val requestBuilder = original.newBuilder()
      //                .addHeader(&quot;Content-Type&quot;, &quot;application/json&quot;)
                  // Adding Authorization token (API Key)
                  val request = requestBuilder.build()
                  chain.proceed(request)
              }
              // }
              return builder.build()
          }
      
          private fun setupRetrofit(context: Context): Retrofit {
              return Retrofit.Builder()
                  .baseUrl(AppConstant.Base_Url)
                  .client(setupOkHttp(context))
                  .addCallAdapterFactory(CoroutineCallAdapterFactory()) // Using create async means all api calls are automatically created asynchronously using OkHttp's thread pool
                  .addConverterFactory(
                      GsonConverterFactory.create(
                          GsonBuilder().registerTypeAdapter(
                              Date::class.java,
                              JsonDeserializer { json, _, _ -&gt; Date(json.asJsonPrimitive.asLong) })
                              .create()
                      )
                  )
                  .build()
          }
       
      }
  
      //viewmodel
  
      
  
      class HuntViewModel(private val huntRepository: HuntRepository) : BaseViewModel() {
          val loginObserver: MutableLiveData&lt;Result&lt;LoginData&gt;&gt; = MutableLiveData()
      
             val loadObserver: MutableLiveData&lt;Boolean&gt; = MutableLiveData()
      
          suspend fun getLoginRequest(body: HashMap&lt;String, String&gt;) {
              try {
                  loadObserver.postValue(true)
                  val userResponse = huntRepository.getLogin(body)
                  if (userResponse != null) {
                      loginObserver.postValue(userResponse)
                  } else {
                      loginObserver.postValue(userResponse)
                  }
              } catch (e: java.lang.Exception) {
                  e.printStackTrace()
              }
          }
  //         ..callapi 
            private fun callLogin(body: HashMap&lt;String, String&gt;) = launch {
              huntViewModel.getLoginRequest(body)
          }
  </code></pre>