0

I have a json file. I want to use this json file with firebase collection and document logic. This is how I created my file. But when I try to read it in my application, I cannot read it like that. I am reading all the files directly. How can I solve this. My code is available below. Also, I mean, for example, when I want the 1st collection, it detects it and takes the values there. When you say 2nd collection, take the ones there. I don't want to take them all.

enter image description here

` fun loadjson(): String? {

    var json:String?=null
    var tur : String = ""
    var ing : String = ""
    var tur_c : String = ""
    var ing_c : String = ""
    var max:Int
    try {

        val inputStream: InputStream = this.requireActivity().assets!!.open("data.json")
     //   json= inputStream.bufferedReader().use(it.readText())

        val size = inputStream.available()
        val buffer = ByteArray(size)
        inputStream.read(buffer)
        inputStream.close()

        json = String(buffer, StandardCharsets.UTF_8)

        val jsonArray = JSONArray(json)
        max=jsonArray.length()


        for (i in 0 until max) {
            val jsonObject = jsonArray.getJSONObject(i)
            tur = jsonObject.getString("tur")
            ing = jsonObject.getString("ing")
            tur_c = jsonObject.getString("tur_c")
            ing_c = jsonObject.getString("ing_c")


            val datafirstt = PhrasalBilgi("1",tur,ing,tur_c,ing_c)


            phrasalbilgi11.add(datafirstt)
        }
        Toast.makeText(context, phrasalbilgi11.get(5).ing, Toast.LENGTH_SHORT).show()


    }

    catch (e:Exception){

    }

    return json
}`
frknklksz
  • 1
  • 1

0 Answers0