cstrap
9/19/2014 - 12:18 PM

Get data from JSON with a regex

Get data from JSON with a regex

/*
* (value) could be (value|tag|name) or whatever is the key on json string
*/
public static String getValueFromJson(String json) {

    String value = "";
    Pattern p = Pattern.compile("\"(value)\":\"((\\\\\"|[^\"])*)\""); 
    Matcher m = p.matcher(json);

    if (m.find() && m.groupCount() > 1) {
        value = m.group(2);
    }

    return value;
}
// ..