Skip to content

Instantly share code, notes, and snippets.

@cstrap
Created September 19, 2014 12:18
Show Gist options
  • Save cstrap/d7cd401203ee680292ad to your computer and use it in GitHub Desktop.
Save cstrap/d7cd401203ee680292ad to your computer and use it in GitHub Desktop.
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;
}
// ..
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment