I have a String like this.
{"type":"broad","Text":"cat"},{"type":"broad","Text":"dog"}
String[] keyString = getParts({"type":"broad","Text":"cat"},{"type":"broad","Text":"dog"});
for(String part : keyString){
some code here which gives like this
String text = "cat";
String type = "broad";
}
Can some one tell me how can i get text and type separately in a string
public static String[] getParts(String keyString) {
if(keyString.isEmpty())
return null;
String[] parts = keyString.split(",");
return parts;
}
Or is there any easy ways to get the respective strings.
This looks like JSON, so if you have / create a class with fields
typeandText, you can use gson or Jackson to parse the string and obtain objects of that class. (You can still split the string withsplit(",")and parse each part as separate JSON string)