从模型获取多个数据

时间:2018-09-27 23:49:40

标签: kotlin retrofit

嗨,我想获取温度,压力,湿度,temp_min和temp_max,并将此信息放入单独的editText字段中。

我的搜索功能:

fun search(city: String) {
    disposable =
            weatherApiService.getWeather(city,apiKey)
                    .subscribeOn(Schedulers.io())
                    .observeOn(AndroidSchedulers.mainThread())
                    .subscribe(
                            {result -> tempTextView.text = "${result.main.temp}"},
                            {error -> Log.e("searchError", error.message)}

                    )
}

我的模特

data class TemperatureFrame(val temp: Double,
                       val pressure: Double,
                       val humidity: Int,
                       val temp_min: Double,
                       val temp_max: Double)

data class Temperature(val main: TemperatureFrame)

我想在此函数中的其他参数上得到类似的东西

{result -> tempTextView.text = "${result.main.temp}"}
{result -> minTempTextView.text = "${result.main.temp_min}"}

1 个答案:

答案 0 :(得分:0)

这正在工作

var data ={
   "Em1": { "c1":"#FFF", "c2":"#EEE" },
   "Em2": { "c1":"#DDD", "c2":"#ooo" }
}


let node = 'Em2';

console.log(data.Em2.c1);
console.log(data.node.c2);