public static void main(String[] args) { String str = "\"{\"TaxCode\":\"91321000071018179B\",\"RetMsg\":\"1011-XXX開啟成功[0000,]\"," + "\"MachineNo\":\"0\",\"TaxClock\":\"2016-11-02 11:21:30\",\"RetCode\":\"1011\"," + "\"IsInvEmpty\":\"0\",\"CorpName\":\"XXXX分公司\",\"CheckCode\":\"661XXX4681\"," + "\"IsLockReached\":\"0\",\"InvLimit\":\"0.0\",\"IsRepReached\":\"0\"}\""; if (str.startsWith("\"")) { str = str.substring(1); } if (str.endsWith("\"")) { str = str.substring(0,str.length() - 1); } System.out.println(str); }
判斷第一位是否為",如果是,返回true,截取第一位。
判斷最後一位是否為",如果是,返回true,截取最後一位。