final String json = "\"name\" : \"john\" , \"worth\" : \"123,456\"";
String[] ss = json.split("\"\\s*,\\s*\"");
System.out.println(json);
for (String s : ss) {
System.out.println("--> " + s);
}
The output is
"name" : "john" , "worth" : "123,456"
--> "name" : "john
--> worth" : "123,456"
Is there any way I can get
"name" : "john" , "worth" : "123,456"
--> "name" : "john"
--> "worth" : "123,456"
Using Regex
While I must agree that using a JSON parser makes a lot more sense, even if you want to use regex, String.split() is not the right tool. Use a Pattern and a Matcher:
Output:
And if you really want to retrieve the quotes, change the pattern to
Output:
Of course this won’t help with different JSON structures like nested object structures, arrays, primitives etc.
Using JSON parsers
But if your question is just about how to do this with JSON parsers, here is an example using JSONObject:
No classes needed. Output: