如何从特定的json密钥android kotlin获取所有数据

如何从特定的json密钥android kotlin获取所有数据,android,json,kotlin,Android,Json,Kotlin,我有一个json响应,如下所示: { "status": "success", "count": 3, "data": [ { "_id": "604b266e7e2dd800159031e4", "type": "expense", "description":

我有一个json响应,如下所示:

{
"status": "success",
"count": 3,
"data": [
    {
        "_id": "604b266e7e2dd800159031e4",
        "type": "expense",
        "description": "This is an income",
        "amount": 4555,
        "createdAt": "2021-03-12T08:29:34.128Z",
        "updatedAt": "2021-03-12T08:29:34.128Z",
        "id": "604b266e7e2dd800159031e4"
    },
    {
        "_id": "604b24ac7e2dd800159031e2",
        "type": "expense",
        "description": "This is an income",
        "amount": 4555,
        "createdAt": "2021-03-12T08:22:04.802Z",
        "updatedAt": "2021-03-12T08:22:04.802Z",
        "id": "604b24ac7e2dd800159031e2"
    },
    {
        "_id": "604b24897e2dd800159031e1",
        "type": "income",
        "description": "This is an income",
        "amount": 4555,
        "createdAt": "2021-03-12T08:21:29.684Z",
        "updatedAt": "2021-03-12T08:21:29.684Z",
        "id": "604b24897e2dd800159031e1"
    }
  ]
}
对象数组中有一个“type”键,其值可以是“费用”或“收入”

现在,在我的安卓系统中,我如何只获取“费用”和“收入”的数据,而不是所有数据

示例我希望运行此请求,但只获取值为“expense”的类型。我怎么和科特林一起做

我正在使用改装

Resource.Status.SUCCESS -> {

  if (it.data?.status == "success") {

       for (expenditureType in it.data.data){

                val type = expenditureType.type
               //logic here 

            }
       } 
 }

如果您想要所有类型的列表

您可以使用map函数获取字符串列表

  val list:List<String> = it.data.data.map {
      it.type
  }

如果您想要所有类型的列表

您可以使用map函数获取字符串列表

  val list:List<String> = it.data.data.map {
      it.type
  }
就这么简单

就这么简单

val expenseList = it.data.data.filter { it.type = "expense" }