我已经离开一个项目大约一年了,但是现在我正重新投入其中。 Kalxon非常先于创建一个数组来从
进行解析{“ towns”:[[“-”,{“ zip”:“ 02054”,“ City”:“ Millis”,“ State”:“ MA”,“ lat”:“ 42.1677”,“ Long” :“-71.3601”},.........}
json数据,但是我对现在该怎么做有点困惑。下面是以前的代码,效果很好。...
我是否认为Klaxon不能像许多其他Java / Json / Android库那样得到充分的文档/文档指导是错误的。
val towns : Parser = Parser()
val townsBuilder: StringBuilder = StringBuilder(data)
val townsjson = towns.parse(townsBuilder) as JsonObject
Log.d("JOO",townsjson.toString())
townInfo = townsjson.array("towns")!!
Log.d("length array retrieve",this.townInfo.size.toString())
if(this.townInfo.size<2){
Toast.makeText(this,"You have entered an invalid zip code",Toast.LENGTH_LONG).show()
}else{
Log.d("type",this.townInfo.javaClass.name) // kotlin.Double
val townListO = ArrayList<MyInfo>()
for (i in townInfo.indices){
Log.d("Loops"+i.toString(),townInfo[i].string("zip"))
townListO.add(MyInfo(townInfo[i].string("City"),townInfo[i].string("zip")))
}