This Stringified JSON array is invalid because the map keys and values are not in quotes but I wanna decode it:
"[{division: bacteriology, speciality: microbiology, tests: [appearence of urine], category: urine}]"
CodePudding user response:
as your string is not in proper json format, so i try to decode this particular string by converting it to proper json-
String data = "[{division: bacteriology, speciality: microbiology, tests: [appearence of urine], category: urine}]";
String formattedDataInJson = data.replaceAll("{", "{\"").replaceAll("}", "\"}").replaceAll(":", "\":\"").replaceAll(",", "\",\"").replaceAll("\"\"", "\"");
String division = jsonDecode(formattedDataInJson)[0]["division"];
CodePudding user response: