I am getting the json data from an API as String but I want to store it in DB and use it as integer. For example I am getting A=15K or 15M but I want 15000.
Here is my class
public class JsonRestApi {
public JsonRestApi() {
try {
String Response = "{\"Youtube Data\":{\"Views\":\"15K\"}}";
JSONParser parser = new JSONParser();
try {
Object obj = parser.parse(Response);
JSONObject jsonObject = (JSONObject) obj;
JSONObject jsonObject3 = (JSONObject)jsonObject.get("Youtube Data");
String yviews = (String)jsonObject3.get("Views");
System.out.println(yviews);
}
}
}
}
Output- 15K
But I want output as 15000. However I do not want to change my Json data. How should I accomplish this?
s = s.replaceFirst("(?i)\\s*K$", "000").replaceFirst("(?i)\\s*M$", "000000").replaceFirst("(?i)\\s*G$", "000000000")