如何基于特定单词截断数组内元素的字符串

问题描述 投票:-1回答:3

我是Java语言的新手,很难进行字符串操作我有一个这样的数组:

myArray = [{
cbID : "1" ,
cbCheckData : "{"request_id":"364165","final_decision":"FAIL","derived_Attribute_1":"PASS|Number of active MFI :0","derived_Attribute_4":"PASS|Total Exposure + Applied Amount :73307.0","derived_Attribute_3":"PASS|Number of Total Active Institutions :2","derived_Attribute_2":"FAIL|Overdue Amount:9828.0","derived_Attribute_5":"PASS|Write off amount:0.0","cbResponseMsg":"Final Decision:FAIL || Number of active MFI :0 || Total Exposure + Applied Amount :73307.0 || Number of Total Active Institutions :2 || FAILOver"}
]

这是我实际的数组结构:

actual array with data

我需要这样输出:

myArray = [{
cbID : "1" ,
cbCheckData : "{"request_id":"364165","final_decision":"FAIL","derived_Attribute_1":"PASS|Number of active MFI :0","derived_Attribute_4":"PASS|Total Exposure + Applied Amount :73307.0","derived_Attribute_3":"PASS|Number of Total Active Institutions :2","derived_Attribute_2":"FAIL|Overdue Amount:9828.0","derived_Attribute_5":"PASS|Write off amount:0.0"}
]

基本上,如果cbData包含单词,“ cbResponseMsg”及其后的单词,则需要截断字符串。

[我是Java语言的新手,在字符串操作方面很难,我有一个像这样的数组:myArray = [{cbID:“ 1”,cbCheckData:“ {” request_id“:” 364165“,” final_decision“:” FAIL “,” ...

javascript arrays substr
3个回答
0
投票

[好吧,首先将您的代码弄乱,在cbData:之后删除引号,然后在JSON对象的末尾插入另一个}。 (在下面的代码中更正)


0
投票

如果cbResponseMsg内有cbData.cbResponseMsg,则会删除myArray


0
投票

由于cbResponseMsg是字符串化的JSON,因此可以在其上使用JSON.parse(),然后使用解构方法删除cbResponseMsg键。您可以使用.map()

© www.soinside.com 2019 - 2024. All rights reserved.