Recursively extracting JSON field values in Groovy
问题 I need to implement a method that will scan a string of JSON for a particular targetField and either return the value of that field (if it exists), or null (if it doesn't): // Ex: extractFieldValue(/{ "fizz" : "buzz" }/, 'fizz') => 'buzz' // Ex: extractFieldValue(/{ "fizz" : "buzz" }/, 'foo') => null String extractFieldValue(String json, String targetField) { // ... } This solution has to be recursive and work at any nesting-level in the (hierarchical) JSON string. Also it needs to work for