我是从一个URL连接得到了一块JSON文本的,目前保存到一个字符串,例如:提取最后小数
...//setting up url and connection
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String str = in.readLine();
当我打印的海峡,我找到正确的数据{"build":{"version_component":"1.0.111"}}
现在我想从str中提取111,但是我遇到了一些麻烦。
我试图 String afterLastDot = inputLine.substring(inputLine.lastIndexOf(".") + 1);
,但我最终111"}}
我需要一个解决方案是通用的,所以,如果我有String str = {"build":{"version_component":"1.0.111111111"}};
解决方案仍然有效,并提取111111111(即我不想硬编码提取物中的小数点后的最后三位数字)
嗯。那么你在哪里使用正则表达式? –
你可以做JSON –
json.getBuild.getVersion_component –