gpt4 book ai didi

Android JSON 解析问题

转载 作者:行者123 更新时间:2023-11-29 18:04:29 25 4
gpt4 key购买 nike

我有一个 json 文件,其中包含一堆不同类别的项目,我想检查类别,如果与给定条件匹配,我想显示在 ListView 中,这就是我想出的..但它没有用, ListView 是空的

ArrayList<HashMap<String, String>> eventsList = new ArrayList<HashMap<String, String>>();

try {
JinnerObject = Jobject.getJSONObject("data");
Jarray = JinnerObject.getJSONArray("events");
for(int i = 0; i < Jarray.length(); i++){
JeventObject = Jarray.getJSONObject(i);

String _EV_OP1 = JeventObject.getString(EV_OP1);
String _EV_OP2 = JeventObject.getString(EV_OP2);
String _EV_COEF1 = JeventObject.getString(EV_COEF1);
String _EV_COEF2 = JeventObject.getString(EV_COEF2);
String _EV_STIME = JeventObject.getString(EV_STIME);
String _EV_HOST = JeventObject.getString(EV_HOST);
String _EV_DESC = JeventObject.getString(EV_DESC);
String _EV_TIP = JeventObject.getString(EV_TIP);
String _EV_CAT = JeventObject.getString(EV_CAT);

if(_EV_CAT == C){
HashMap<String, String> Events_map = new HashMap<String, String>();

Events_map.put(EV_OP1, _EV_OP1);
Events_map.put(EV_OP2, _EV_OP2);
Events_map.put(EV_COEF1, _EV_COEF1);
Events_map.put(EV_COEF2, _EV_COEF2);
Events_map.put(EV_STIME, _EV_STIME);
Events_map.put(EV_HOST, _EV_HOST);
Events_map.put(EV_DESC, _EV_DESC);
Events_map.put(EV_TIP, _EV_TIP);

eventsList.add(Events_map);
}
}
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

最佳答案

改变

if(_EV_CAT == C)

if(_EV_CAT.equalsIgnoreCase(C))

比较字符串总是使用equalsIgnoreCaseequals 因为== 运算符比较两个对象引用以查看它们是否引用相同的实例

关于Android JSON 解析问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14111526/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com