gpt4 book ai didi

android - 比较 2 个 JSONObject

转载 作者:行者123 更新时间:2023-11-30 03:11:18 24 4
gpt4 key购买 nike

我的问题是这样的:https://stackoverflow.com/questions/20919343/php-getting-count-of-how-many-x-and-y-in-a-row-then-getting-other-data-of-x-and

但后来我想到了从 Android 部分来完成这项工作。所以我有 2 个从 php 生成的 JSONObjects。第一个对象有“value”和“total”数组。第二个有“姓名”、“姓氏”和“号码”以及更多数组。现在我需要比较第二个 JSONObject 的数字和第一个的值。我尝试了一些循环,但它按预期创建了 double。这是我的 onPostExecute 方法:

protected void onPostExecute(Void result) {
// TODO Auto-generated method stub
super.onPostExecute(result);
pDialog.dismiss();
try {
JSONObject jsonObj = new JSONObject(jsonStr);
JSONObject jsonObj2 = new JSONObject(jsonStr);

// Getting JSON Array node
sonuc = jsonObj.getJSONArray(TAG_BASLIK);

// looping through All Contacts
for (int i = 0; i < sonuc.length(); i++) {
JSONObject c = sonuc.getJSONObject(i);

AdayNumara = c.getString(TAG_OY);
ToplamOy = c.getString(TAG_TOPLAM);

Log.i("Aday Numaraları", AdayNumara);
Log.i("Oy Sayısı", ToplamOy);



pie.addItem(AdayNumara,Float.valueOf(ToplamOy), pRenk.get(i));

adaylar = jsonObj2.getJSONArray(TAG_ADAYLAR);
for(int j=0; j< adaylar.length(); j++){

JSONObject c2 = adaylar.getJSONObject(j);

String no = c2.getString(TAG_NO);
String ad = c2.getString(TAG_AD);
String soyad = c2.getString(TAG_SOYAD);
String resim = c2.getString(TAG_RESIM);



HashMap<String, String> aday = new HashMap<String, String>();

do{
aday.put(TAG_AD, ad);
aday.put(TAG_SOYAD, soyad);
aday.put(TAG_RESIM, resim);
aday.put(TAG_NO, no);
aday.put(TAG_TOPLAM, ToplamOy);

adayList.add(aday);} while(AdayNumara == no);
}

adapter=new LazyAdapter2(SecimSonuclari.this, adayList);
lv.setAdapter(adapter);
}



}catch (JSONException e) {
e.printStackTrace();
}


}

代码可能有错误的方法,因为我是 Android 的新手。

我现在得到的是 ListView 中的值。必须有 2。前两个在其数字行上具有相同的值,如 1 和 1。第二对有另一个数字,比方说 2。

最佳答案

我发现了我的问题。使用“==”似乎是错误的。

if(AdayNumara.equals(no)){
aday.put(TAG_AD, ad);
aday.put(TAG_SOYAD, soyad);
aday.put(TAG_RESIM, resim);
aday.put(TAG_NO, no);
aday.put(TAG_TOPLAM, ToplamOy);

adayList.add(aday);

}

关于android - 比较 2 个 JSONObject,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20935021/

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