gpt4 book ai didi

java - 我需要从 JSON 对象中删除特定标签

转载 作者:行者123 更新时间:2023-12-02 01:33:12 33 4
gpt4 key购买 nike

我有一个 JSON 对象,如下

{
"mandator":"GB0010001",
"debitAccount":"81884",
"creditAccount":"82918",
"trustedBeneficiary":"false",
"localCurrencyAmount":35,
"transactionReference":"omega7.1.1",
"debitAccountASPSP":"t24",
"currencyAmount":35,
"executionDate":"20180102",
"creditAccountASPSP":"t24",
"transactionType":"Contactless payment",
"trustedPSP":"false",
"jsonErrorResponse":{
"errorCount":0,
"errors":[

]
},
"currency":"USD",
"company":"GB0010001"
}

我需要删除"jsonErrorResponse":{"errorCount":0,"errors":[]} ,我用过JSONobject.remove("jsonErrorResponse").toString()

但它给我的输出为 {"errorCount":0,"errors":[]}而不是

{
"mandator":"GB0010001",
"debitAccount":"81884",
"creditAccount":"82918",
"trustedBeneficiary":"false",
"localCurrencyAmount":35,
"transactionReference":"omega7.1.1",
"debitAccountASPSP":"t24",
"currencyAmount":35,
"executionDate":"20180102",
"creditAccountASPSP":"t24",
"transactionType":"Contactless payment",
"trustedPSP":"false",
"currency":"USD",
"company":"GB0010001"
}

最佳答案

JSONobject.remove("jsonErrorResponse") 返回已删除的内容。您正在对刚刚“删除”的部分调用 toString

不要链接方法调用。

JSONobject.remove("jsonErrorResponse");
String newJson = JSONobject.toString()

关于java - 我需要从 JSON 对象中删除特定标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55704723/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com