我有一个像下面这样的json字符串。
oncomptetion({
"competition": [
{
"CompetitionID": "7b47afgwi2017odi",
"CompetitionName": "AFGHANISTAN IN WESTINDIES ODI SERIES 2017",
"DivisionID": "1",
"DivisionName": "1 Division",
"MappingCompName": "",
"CompetitionType": "One Day Match"
},
{
"CompetitionID": "7b4785be057b448f",
"CompetitionName": "AFGHANISTAN IN WESTINDIES T20I SERIES 2017",
"DivisionID": "1",
"DivisionName": "1 Division",
"MappingCompName": "",
"CompetitionType": "T20 Match"
}]
})
我想从字符串中删除/删除第一个和最后一个左括号并包含 oncomptetion 此名称。
请帮帮我
答案 0 :(得分:0)
尝试此操作以获得有效的Json
String json="your Srting"; //unformatted string
String output = json.replace("oncomptetion(", ""); //removing oncomptetion(
String finalJson= output.substring(0, output.length() - 1); //removing last string )
System.out.println(""+finalJson);
输出:
{ "competition": [
{
"CompetitionID": "7b47afgwi2017odi",
"CompetitionName": "AFGHANISTAN IN WESTINDIES ODI SERIES 2017",
"DivisionID": "1",
"DivisionName": "1 Division",
"MappingCompName": "",
"CompetitionType": "One Day Match"
},
{
"CompetitionID": "7b4785be057b448f",
"CompetitionName": "AFGHANISTAN IN WESTINDIES T20I SERIES 2017",
"DivisionID": "1",
"DivisionName": "1 Division",
"MappingCompName": "",
"CompetitionType": "T20 Match"
}]
}