if your text is always in that format and you do not want to parse it using JSON, then you can do the following.
do your own error checking and sanity check.
(handle the presence/absence of spacing, search key not found, etc)
public static void main(String []args){
String s1 = " \"{\"measurements\": [\"528391^MDC_DEV_SPEC_PROF^M12343\"], \"metrics\": [\"150021^MDC_PRESS_BLD_NONIN234^MDC\", \"150022^MDC_PRESS_BLD_NONINV_DIA^MDC\", \"150023^MDC_PRESS_BLD_12344^MDC\", \"149546^MDC_PULS_RATE_INV^MDC\"], \"accessoryTypes\": [] }\"";
String testString = "measurements\": [\"";
String endString = "\"],";
System.out.println(s1);
String result = getValue(s1, testString, endString);
System.out.println("RESULT = "+result);
}
public static String getValue(String s1, String keyString, String endString){
int from = s1.indexOf(keyString) + keyString.length();
int to = s1.substring(from).indexOf(endString);
return s1.substring(from, from+to);
}
you result will be like the following
$java -Xmx128M -Xms16M HelloWorld
"{"measurements": ["528391^MDC_DEV_SPEC_PROF^M12343"], "metrics": ["150021^MDC_PRESS_BLD_NONIN234^MDC", "150022^MDC_PRESS_BLD_NONINV_DIA^MDC", "150023^MDC_PRESS_BLD_12344^MDC", "149546^MDC_PULS_RATE_INV^MDC"], "accessoryTypes": [] }"
RESULT = 528391^MDC_DEV_SPEC_PROF^M12343