我有一个长字符串,它是一个 json 文件内容。在这个字符串的某个地方,它包含以下内容:“totalWinAmount”:100
为了找到并返回这个值,我目前正在这样做:
int totalWinAmountIndex = line.lastIndexOf("totalWinAmount");
String resultTotalWinAmount = line.substring(totalWinAmountIndex + 16, totalWinAmountIndex + 19);
这有效,resultTotalWinAmount 正确设置为 100,但我很好奇这是否是这种情况的最佳实践,这是否真的是糟糕的编码,或者是否有更好的方法?