Parse JSON file using GSON

Imo, the best way to parse your JSON response with GSON would be creating classes that “match” your response and then use Gson.fromJson() method. For example: class Response { Map<String, App> descriptor; // standard getters & setters… } class App { String name; int age; String[] messages; // standard getters & setters… } Then just …

Read more

Why double.TryParse(“0.0000”, out doubleValue) returns false ?

it takes the localization settings at runtime into account… perhaps you are running this on a system where . is not the decimal point but , instead… In your specific case I assume you want a fixed culture regardless of the system you are running on with . as the decimal point: double.TryParse(“0.0000”, NumberStyles.Number, CultureInfo.CreateSpecificCulture …

Read more

Regular expression to select all whitespace that isn’t in quotes?

Here’s a single regex-replace that works: \s+(?=([^”]*”[^”]*”)*[^”]*$) which will replace: (this is a test “sentence for the regex” foo bar) with: (thisisatest”sentence for the regex”foobar) Note that if the quotes can be escaped, the even more verbose regex will do the trick: \s+(?=((\\[\\”]|[^\\”])*”(\\[\\”]|[^\\”])*”)*(\\[\\”]|[^\\”])*$) which replaces the input: (this is a test “sentence \”for the regex” …

Read more