Hey guys, anyone can help me how to manage my prob...
# klaxon
d
Hey guys, anyone can help me how to manage my problem? Lets say i need to pull a json in one endpoint that may have thousands item in them. and their format is something like this :
Copy code
{
 "records" : [
 {
   "field": value ,
   "field": value
 },
 {
   "field": value,
   "field": value
 },
// etc until xxx times
}
how i can parse the
records
? I know and already can parse the data inside
records
, but i m not sure how to get
records
. I already try to parse it with this code :
Copy code
class Records(val Records:List<Any>? = null)
but its failed.
@cedric any idea ?
c
How did it fail? Also, if there are so many elements, consider using the streaming API, night work better for you
Also you parameter should be called
records
(lowercase 'r')
d
oh sorry it was :
Copy code
{
 "Records" : [
  { blablabla }
}
and well, isn't streaming one just possible if the API not give you all the data in one bundle? in my case the API send me all the data in one bundle. Damn.
wait, i can't tell so much, need to re-debugging for it. gonna tell you asap 😄 thanks for reply tho
c
No you can always use streaming
d
this one right?
Wait, i just read it. So i don't need to parse
Records
field specifically right? I can ignore everything then? and just use the streaming?
@cedric sry, are u busy cedric? idk, where is wrong, i got this error :
Unexpected character at position 1: 'j' (ASCII: 106)'
my code is this :
Copy code
val respondItem = String(response.data) // change the json i got from api to string
                    val records = Klaxon().parse<Records>(respondItem) //parse it like usual
                    val recordsString = records?.Records.toString() //change result to string
                    val item = Klaxon().parse<Item>(recordsString) // parse it again and error occured here
and this is my class data file :
Copy code
class Records(val Records: List<Item>)

class Item(
    val ID: Long,
    val Kode: String,
    val Kode2: String,
    val GrpStkID: Int,
    val GroupStk: String,
    val GrpSt2ID: Int,
    val GroupSt2: String,
    val GrpSt3ID: Int,
    val GroupSt3: String,
    val Nama: String,
    val HargaBeli: String,
    val HargaJual1: String,
    val HargaJual2: String,
    val HargaJual3: String,
    val HargaJual4: String,
    val HargaJual5: String,
    val HargaJual1Nilai: Double,
    val HargaJual2Nilai: Double,
    val HargaJual3Nilai: Double,
    val HargaJual4Nilai: Double,
    val HargaJual5Nilai: Double,
    val HargaJual1Sat: Int,
    val HargaJual2Sat: Int,
    val HargaJual3Sat: Int,
    val HargaJual4Sat: Int,
    val HargaJual5Sat: Int,
    val Sat_K_01: Float,
    val Sat_K_02: Float,
    val Sat_K_03: Float,
    val Sat_K_04: Float,
    val Sat_K_05: Float,
    val Sat_K_06: Float,
    val Sat_K_07: Float,
    val Sat_K_08: Float,
    val Sat_K_09: Float,
    val Sat_K_10: Float
)
got any idea why?
c
Something seems wrong in your JSON but you didn’t include it here
d
i think its a valid one, since i check it with json validator