Попытка разделения с использованием запятой в качестве разделителя в строке и добавления в строковый массив, но возникает проблема при разделении строки с помощью регулярного выражения.
String[] stringParts = str1.split(",(?![^\\[]*\\])");
for (int i=0; i<stringParts.length; i++){
stringParts[i] = stringParts[i].trim();//remove trailing leading spaces.
}
//System out
for (String s:stringParts){
System.out.println(s);
}
Input String
String str="1, two, {\"\"Customization\"\":{\"\"EMPLOYEEID\"\":\"\"EMPID001\"\",\"\"MANAGER_ID\"\":\"\"MNGID001\"\",\"\"DEPARTMENT\"\":\"\"IT\"\"},\"\"OTHERDETAILS\"\":{\"\"GENDER\"\":\"\"M\"\",\"\"DESIGNATION\"\":\"\"SENIOR\"\",\"\"TEAM\"\":\"\"QA\"\"}}, 8, nine,{{\"COMPANYNAME\":\"XYZ Ind Pvt Ltd\"},{[ten,{\"11\":\"12\"},{\"thirteen\":14}]}},\"fifteen\",16";
Требуемый выход
1
two
{""Customization"":{""EMPLOYEEID"":""EMPID001"",""MANAGER_ID"":""MNGID001"",""DEPARTMENT"":""IT""},""OTHERDETAILS"":{""GENDER"":""M"",""DESIGNATION"":""SENIOR"",""TEAM"":""QA""}}
8
nine
{{"COMPANYNAME":"XYZ Ind Pvt Ltd"},{[ten,{"11":"12"},{"thirteen":14}]}}
fifteen
16