没有密钥的Json数组不是故意的

时间:2019-09-13 13:04:37

标签: android arrays json android-intent kotlin

我可以在 moviedb api 中使用 json 数据。我想使用genre_ids。我获取了 json 数组,但我没有进行任何活动,因为我的意图返回了0.我想显示genre_ids数字。在这里 json 数据和下面的一些代码:

{
    "page":1,
     "results":[
      {
          "genre_ids":[
            28,
            12,
            878
           ]
      }
   ]
}

HomeFragment

                override fun onResponse(response: JSONObject?) {
                    var tur = response?.getJSONArray("results")


                    for (i in 0 until tur!!.length()) {
                        val film = Movie()
                        var jsonObj = tur.getJSONObject(i)
                        film.title = jsonObj.getString("title")
                        film.releaseDate = jsonObj.getString("release_date")
                        film.posterPath = jsonObj.getString("poster_path")
                        film.voteAverage = jsonObj.getString("vote_average")
                        film.overView = jsonObj.getString("overview")


                        var deneme = jsonObj.getJSONArray("genre_ids")
                        for (j in 0 until deneme.length()) {
                            film.genreIds = deneme.getInt(j)
                            Log.e("c", deneme.getInt(j).toString())
                        }
}

DetailActivity

 override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_movie_detail)
        var baslik = intent.extras.getString("title")
        tvDetayBaslik.text = baslik
        var resim = intent.extras.getString("image")
        var url = "https://image.tmdb.org/t/p/w500"
        var poster = Glide.with(this).asBitmap().load(url + resim).into(imgPosterDetay)
        var tarih = intent.extras.getString("date")
        tvDetayTarih.text = tarih
        var puan = intent.extras.getString("point")
        if (puan=="0.0"){
            tvDetayPuan.text="Puan yok"
        }else {
            tvDetayPuan.text = puan.toString()
        }

        var aciklama = intent.extras.getString("description")
        if (aciklama == "") {
            tvDetayOverview.text = "Açıklama Yapılmamıştır."
        } else {
            tvDetayOverview.text = aciklama
        }

       var turId=intent.extras.getInt("id")
        Log.e("cagla", intent.extras.getInt("id").toString())

0 个答案:

没有答案