我在登录页面中有一个编辑文本,并且我有一个编辑文本MaxLength="12“的条件。在我的JSON响应中,我有一个包含15个字母(或Nor's)的字符串,我需要检查(或比较)其中的12个字母(或Nor's),如果两个字母在12个字母(或Nor‘s)之前相同,那么我必须进入我的应用程序。
{
ID No="123456789012.00"
}
发布于 2017-02-11 20:25:35
Hello Suresh使用String#substring
try {
JSONObject jObj = new JSONObject("{\"id_no\":\"123456789012.00\"}");
String strJNumber = jObj.optString("id_no").substring(0,11);
String strENumber = etNumber.getText().toString();
if(strENumber.equals(strJNumber)){
// TODO: true both are same
}else {
// TODO: true both are not same
}
} catch (JSONException e) {
e.printStackTrace();
}
发布于 2017-02-11 20:24:00
你可以使用"substring“和"equals”方法:(我假设你的字符串的名字是editTextString和jsonString)
首先,从json string中获取前12个字符的子串:
String jsonFirst12Chars = jsonString.substring(0,12);
然后使用equals方法对它们进行比较:
if(editTextString.equals(jsonFirst12Chars)) {
// They are same, do something
} else {
// They are not same..
}
https://stackoverflow.com/questions/42175516
复制相似问题