jsonarry uchun json parserim faqat birinchi elementni olishadi

json majmuasini ajratadigan va qayta ro'yxatlash adapterida foydalanadigan va keyin adapterni qayta ishlanadigan ma'lumotlar majmuasi yordamida ishlatadigan ayrıştırıcı funktsiyasiga ega ekanligimni bildiraman .da menga haqiqiy uzunligini berib turadi, lekin faqatgina birinchi elementlar to'ldiriladi, qolganlar NULL

bu mening kodim

 public void parsee_item() {
    JSONObject jsonObject = null;
    try {
        jsonObject = new JSONObject(json);
       final JSONArray userss = jsonObject.getJSONArray(JSON_ARRAY);
        item_id = new String[userss.length()];
        item_owner = new String[userss.length()];
        item_images = new String[userss.length()];
        item_names = new String[userss.length()];
        item_price = new String[userss.length()];
        item_place = new String[userss.length()];


        JSONObject jo = null;
        for (int i = 0; i < userss.length();i++) {
            jo = userss.getJSONObject(i);
            Log.d("alrsp", jo.toString());
            item_id[i] = jo.getString(KEY_ID);
            item_owner[i] = jo.getString(KEY_OWNER);
            item_images[i] = jo.getString(KEY_IMAGE);
            item_names[i] = jo.getString(KEY_NAME);
            item_price[i] = jo.getString(KEY_PRICE);


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

json

   {
    "result": [{
        "item_id": "10",
        "owner": "user",
        "item_type_id": "1",
        "url1": "http:\/\/localhost:8080\/market\/items\/14.1.png",
        "name": "jc",
        "price": "76"
    }, {
        "item_id": "12",
        "owner": "user",
        "item_type_id": "1",
        "url1": " http:\/\/localhost:8080\/market\/items\/14.1.png",
        "name": "nzbsbsb",
        "price": "0"
    }, {
        "item_id": "13",
        "owner": "user",
        "item_type_id": "1",
        "url1": " http:\/\/localhost:8080\/market\/items\/14.1.png",
        "name": "uygf",
        "price": "0"
    }]
}

and this screenshot of the list enter image description here

1
jo = userss.getJSONObject (i); jo = userss.getJSONObject (4);
qo'shib qo'ydi muallif SRB bans, manba
Iltimos, savolda misol json qo'shing.
qo'shib qo'ydi muallif Srikanth A, manba
disk raskadrovka va qator kattaligi tekshirilsin, agar u 1dan ortiq bo'lsa, keyin siz adapter sinfini getCount ()
qo'shib qo'ydi muallif Mrinmoy, manba
Siz uchun formani "for (int i = 0; i
qo'shib qo'ydi muallif lal, manba
Afsuski, men buni faqat sinov maqsadlarida qildim, lekin bu haqiqiy koddir
qo'shib qo'ydi muallif Mohamed S Alwali, manba

7 javoblar

Siz o'zingizni jsonlarni ajratish taklif etilmaydi, Gson yoki fastJson o'rniga.

2
qo'shib qo'ydi
@Op Agar siz ayniqsa o'zingiz kerak bo'lmagan narsalarni o'zingiz aylantirmasangiz, umuman jamoa har qanday shaxsdan ancha aqlli bo'lishi kerak.
qo'shib qo'ydi muallif Machinarius, manba

enter image description here

Men sizning kodingizni ishlatdingiz, disk raskadrovka qildingiz va qiymatlar yangilandi, ularning JSON paring bilan xato emas, shuning uchun qayta ishlovchi ko'rinish adapter kodingizni tekshiring yoki uni ulashing

1
qo'shib qo'ydi
     JSONObject jo = null;
    for (int i = 0; i < userss.length();i++) {
        jo = userss.getJSONObject(i);
        Log.d("alrsp", jo.toString());
        item_id[i] = jo.getString(KEY_ID);
        item_owner[i] = jo.getString(KEY_OWNER);
        item_images[i] = jo.getString(KEY_IMAGE);
        item_names[i] = jo.getString(KEY_NAME);
        item_price[i] = jo.getString(KEY_PRICE);
        item_place[i] = jo.getString("place");


    }
0
qo'shib qo'ydi
json yozing ...
qo'shib qo'ydi muallif user2025187, manba
Afsuski, men buni faqat sinov maqsadlarida qildim, lekin bu haqiqiy koddir
qo'shib qo'ydi muallif Mohamed S Alwali, manba

ur kodi bilan bog'liq muammo siz qattiq kodning qiymati 4 dan foydalansangiz

  jo = userss.getJSONObject (4);
 
-ni tanlang

Ushbu foydalanishdan bexabar

    jo = userss.getJSONObject(i);

indeksni 4 jsonObject ma'lumotlarini ajratib olayotganda har doim

public void parsee_item() {
    JSONObject jsonObject = null;
    try {
        jsonObject = new JSONObject(json);
       final JSONArray userss = jsonObject.getJSONArray(JSON_ARRAY);
        item_id = new String[userss.length()];
        item_owner = new String[userss.length()];
        item_images = new String[userss.length()];
        item_names = new String[userss.length()];
        item_price = new String[userss.length()];
        item_place = new String[userss.length()];


    JSONObject jo = null;
    for (int i = 0; i < userss.length();) {
        jo = userss.getJSONObject(i);
        Log.d("alrsp", jo.toString());
        item_id[i] = jo.getString(KEY_ID);
        item_owner[i] = jo.getString(KEY_OWNER);
        item_images[i] = jo.getString(KEY_IMAGE);
        item_names[i] = jo.getString(KEY_NAME);
        item_price[i] = jo.getString(KEY_PRICE);
        item_place[i] = jo.getString("place");
        i++;

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

}

Agar siz bunday turdagi ajratishni ishlatsangiz, bu bo'sh ko'rsatkichni istisno qilishga olib kelishi mumkin

0
qo'shib qo'ydi

Quyidagi kabi JSON ustidan tahlil qilishingiz mumkin

private void jsonParse(String response) throws JSONException {
        JSONObject jsonObject = new JSONObject(response);
        JSONArray jsonArray = jsonObject.getJSONArray("result");
        if (jsonArray != null && jsonArray.length() > 0) {
            for (int i = 0; i < jsonArray.length(); i++) {
                JSONObject object = jsonArray.getJSONObject(i);
                if (object != null) {
                    String itemId = object.getString("item_id");
                    String owner = object.getString("owner");
                    String item_type_id = object.getString("item_type_id");
                    String url1 = object.getString("url1");
                    String name = object.getString("name");
                    String price = object.getString("price");
                }
            }
        }
    }
0
qo'shib qo'ydi

Ushbu qatorni almashtirish

jo = userss.getJSONObject(4);

bu bilan

jo = userss.getJSONObject(i);
0
qo'shib qo'ydi
json bilan bo'lishishi mumkinmi?
qo'shib qo'ydi muallif ak sacha, manba
Afsuski, men buni faqat sinov maqsadlarida qildim, lekin bu haqiqiy koddir
qo'shib qo'ydi muallif Mohamed S Alwali, manba

jsonarray tomonidan yuborilmaydigan parametr qabul qilindim

item_place[i] = jo.getString("place")
0
qo'shib qo'ydi