Android 解析器JSON没有响应,因为它应该响应
我试图从我的JSON对象中检查一些细节,但问题是当我从JSON获取数据并与另一个对象进行比较时,有一个我无法理解的问题 我试图从JSON中获取“status”(string of true/false)字段,并将其与string of true string进行比较,然后从JSON中打印另一个字段。问题是,即使它需要true==true,它也不会进入if段 JSON对象-Android 解析器JSON没有响应,因为它应该响应,android,json,Android,Json,我试图从我的JSON对象中检查一些细节,但问题是当我从JSON获取数据并与另一个对象进行比较时,有一个我无法理解的问题 我试图从JSON中获取“status”(string of true/false)字段,并将其与string of true string进行比较,然后从JSON中打印另一个字段。问题是,即使它需要true==true,它也不会进入if段 JSON对象- [ { "latitude":"33.33", "longitude":"44.44",
[
{
"latitude":"33.33",
"longitude":"44.44",
"name":"test1",
"Notification":"true",
"status":"true"
},
{
"latitude":null,
"longitude":null,
"name":null,
"Notification":null,
"status":"false"
}
]
试试看{
JSONArray JSONArray=新JSONArray(答案);
for(int i=0;i
如果有人能帮助我了解问题所在,我会很高兴。谢谢。用这个
try {
JSONArray jsonarray = new JSONArray(answer);
for (int i = 0; i < jsonarray.length() - 1; i++) {
JSONObject jsonobject = jsonarray.getJSONObject(i);
String a = jsonobject.getString("status"); // for the first is true and the second is false
if(a.equals("true")){ // not enter to this if a equal to true
Log.d("test",jsonobject.getString("status"));
}
}
}catch(Exception e)
{
e.printStackTrace();
}
试试看{
JSONArray JSONArray=新JSONArray(答案);
for(int i=0;i
如果(a.toString().equals(“true”))尝试this@ZakiPathan谢谢现在开始工作,并从for循环中删除-1。如果你想要-1,那么把条件作为我欢迎兄弟。很高兴提供帮助:):)您不应该使用相等运算符来比较字符串,而应该这样比较a.equals(“true”)
或a.equalsIgnoreCase(“true”)
请将其标记为正确,以便将来任何人都可以使用它。
try {
JSONArray jsonarray = new JSONArray(answer);
for (int i = 0; i < jsonarray.length() - 1; i++) {
JSONObject jsonobject = jsonarray.getJSONObject(i);
String a = jsonobject.getString("status"); // for the first is true and the second is false
if(a.equals("true")){ // not enter to this if a equal to true
Log.d("test",jsonobject.getString("status"));
}
}
}catch(Exception e)
{
e.printStackTrace();
}