本文介绍了rxkotlin groupby无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

能否请您帮我按以下json分组,并根据RxKotlin的日期在kotlin中返回hashMap?仅用Kotlin是如此容易,但对于Rxkotlin来说确实很困难.谢谢

val groupedTransactions = accountTransactions.transactions ?.groupBy {it.effectiveDate}

"transactions": [{
        "id": "44e5b2bc484331ea24afd85ecfb212c8",
        "effectiveDate": "20/07/2017",
        "description": "Kaching TFR from JOHN CITIZEN<br/>xmas donation",
        "amount": 12.00
    }, {
        "id": "1506aeeb8c3a699b1e3c87db03156428",
        "effectiveDate": "20/07/2017",
        "description": "Wdl ATM CBA ATM CIRCULAR QUAY STATION NSW 221092 AUS",
        "amount": -200.00,
        "atmId": "129382"
    }, {
        "id": "9a899bfd978511e9605774e1d5222b67",
        "description": "Savings",
        "effectiveDate": "19/07/2017",
        "amount": 10.00
    }, {
        "id": "1a6c48627cecaa2388b702fa33d751ff",
        "description": "PTAG COCA COLA AMATI",
        "effectiveDate": "12/07/2017",
        "amount": -2.20
    }, {
        "id": "7ecc19e1a0be36ba2c6f05d06b5d3058",
        "description": "Wdl ATM CBA ATM TOWN HALL SQUARE NSW 253432 AUS",
        "effectiveDate": "04/07/2017",
        "amount": -50.00,
        "atmId": "137483"
    }, {
        "id": "b71bf065b640217dad602f86ac047722",
        "description": "BPAY - Telstra mobile",
        "effectiveDate": "04/07/2017",
        "amount": -49.00
    },{
        "id": "ef087651eb482bae4624478696f4ad4f",
        "description": "Transfer from REBECCA SHAW<br/>Lorem ipsum",
        "effectiveDate": "03/07/2017",
        "amount": 150.00
    }, {
        "id": "8cd283d8b7bacc277f2bae5e26ce6d1e",
        "description": "Savings",
        "effectiveDate": "01/07/2017",
        "amount": 200.00
    }, {
        "id": "04117d2d74f5331f3ee4955da27cca7a",
        "effectiveDate": "28/06/2017",
        "description": "Transfer - Saturday drinks",
        "amount": -100.00
    }, {
        "id": "821ae63dbe0c573eff8b69d451fb21bc",
        "effectiveDate": "21/06/2017",
        "description": "Wdl ATM CBA ATM CIRCULAR QUAY STATION NSW 221092 AUS",
        "amount": -200.00,
        "atmId": "129382"
    }]
解决方案

这看起来很像rxkotlin问题.我已经通过协程科特林完成了它,例如:

doAsync { val groupedTransactions = accountTransactions.transactions ?.groupBy { it.effectiveDate } ....

could you please help me to group by the following json and return a hashMap in kotlin based on date with RxKotlin? is so easy with just kotlin but really stuck for Rxkotlin. thanks

val groupedTransactions = accountTransactions.transactions ?.groupBy { it.effectiveDate }

"transactions": [{
        "id": "44e5b2bc484331ea24afd85ecfb212c8",
        "effectiveDate": "20/07/2017",
        "description": "Kaching TFR from JOHN CITIZEN<br/>xmas donation",
        "amount": 12.00
    }, {
        "id": "1506aeeb8c3a699b1e3c87db03156428",
        "effectiveDate": "20/07/2017",
        "description": "Wdl ATM CBA ATM CIRCULAR QUAY STATION NSW 221092 AUS",
        "amount": -200.00,
        "atmId": "129382"
    }, {
        "id": "9a899bfd978511e9605774e1d5222b67",
        "description": "Savings",
        "effectiveDate": "19/07/2017",
        "amount": 10.00
    }, {
        "id": "1a6c48627cecaa2388b702fa33d751ff",
        "description": "PTAG COCA COLA AMATI",
        "effectiveDate": "12/07/2017",
        "amount": -2.20
    }, {
        "id": "7ecc19e1a0be36ba2c6f05d06b5d3058",
        "description": "Wdl ATM CBA ATM TOWN HALL SQUARE NSW 253432 AUS",
        "effectiveDate": "04/07/2017",
        "amount": -50.00,
        "atmId": "137483"
    }, {
        "id": "b71bf065b640217dad602f86ac047722",
        "description": "BPAY - Telstra mobile",
        "effectiveDate": "04/07/2017",
        "amount": -49.00
    },{
        "id": "ef087651eb482bae4624478696f4ad4f",
        "description": "Transfer from REBECCA SHAW<br/>Lorem ipsum",
        "effectiveDate": "03/07/2017",
        "amount": 150.00
    }, {
        "id": "8cd283d8b7bacc277f2bae5e26ce6d1e",
        "description": "Savings",
        "effectiveDate": "01/07/2017",
        "amount": 200.00
    }, {
        "id": "04117d2d74f5331f3ee4955da27cca7a",
        "effectiveDate": "28/06/2017",
        "description": "Transfer - Saturday drinks",
        "amount": -100.00
    }, {
        "id": "821ae63dbe0c573eff8b69d451fb21bc",
        "effectiveDate": "21/06/2017",
        "description": "Wdl ATM CBA ATM CIRCULAR QUAY STATION NSW 221092 AUS",
        "amount": -200.00,
        "atmId": "129382"
    }]
解决方案

this looks lik the rxkotlin issue. I've done it through coroutine kotlin like:

doAsync { val groupedTransactions = accountTransactions.transactions ?.groupBy { it.effectiveDate } ....

这篇关于rxkotlin groupby无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 17:32