Android - 如何在索引处解析带有对象的json

Lms*_*art 3 java parsing android json

我是初学者,所以当json数据没有密钥时,我不知道如何解析json

这是我的Json数据

[
            {
                "products_id":10052,
                "products_name":"\u0e08\u0e35\u0e19 : The Haven Sword and Dragon Sabre - \u0e01\u0e23\u0e30\u0e1a\u0e35\u0e48\u0e1f\u0e49\u0e32\u0e14\u0e32\u0e1a\u0e21\u0e31\u0e07\u0e01\u0e23 1994 **\u0e1a\u0e32\u0e07\u0e15\u0e2d\u0e19\u0e2d\u0e32\u0e08\u0e44\u0e21\u0e48\u0e15\u0e48\u0e2d\u0e40\u0e19\u0e37\u0e48\u0e2d\u0e07\u0e15\u0e49\u0e2d\u0e07\u0e02\u0e2d\u0e2d\u0e20\u0e31\u0e22**",
                "products_description":"<P>\u0e19\u0e31\u0e01\u0e41\u0e2a\u0e14\u0e07:<BR>- \u0e2b\u0e21\u0e48\u0e32\u0e08\u0e34\u0e48\u0e07\u0e40\u0e17\u0e32 (Steven Ma Jing Tao) \u0e23\u0e31\u0e1a\u0e1a\u0e17 \u0e40\u0e15\u0e35\u0e22\u0e1a\u0e48\u0e2d\u0e01\u0e35\u0e49 \u0e01\u0e31\u0e1a...",
                "products_date_available":"0",
                "products_image":"100909-TheHavenSword.jpg",
                "addDate":"2010-10-24 09:59:58"
            },
            {
                "products_id":10117,
                "products_name":"Nogizaka Haruka no Himitsu - \u0e04\u0e27\u0e32\u0e21\u0e25\u0e31\u0e1a\u0e02\u0e2d\u0e07\u0e22\u0e31\u0e22\u0e04\u0e38\u0e13\u0e2b\u0e19\u0e39 Season 1 + 2 (\u0e1a\u0e23\u0e23\u0e22\u0e32\u0e22\u0e44\u0e17\u0e22) **\u0e02\u0e2d\u0e2d\u0e20\u0e31\u0e22\u0e1a\u0e32\u0e07\u0e15\u0e2d\u0e19\u0e20\u0e32\u0e1e\u0e44\u0e21\u0e48\u0e15\u0e23\u0e07\u0e01\u0e31\u0e1a\u0e40\u0e2a\u0e35\u0e22\u0e07\u0e40\u0e19\u0e37\u0e48\u0e2d\u0e07\u0e08\u0e32\u0e01\u0e15\u0e49\u0e19\u0e09\u0e1a\u0e31\u0e1a**",
                "products_description":"<P>Nogizaka Haruka \u0e19\u0e32\u0e07\u0e40\u0e2d\u0e01\u0e02\u0e2d\u0e07\u0e40\u0e23\u0e37\u0e48\u0e2d\u0e07\u0e19\u0e35\u0e49 \u0e40\u0e1b\u0e47\u0e19\u0e44\u0e2d\u0e14\u0e2d\u0e25\u0e2b\u0e19\u0e36\u0e48\u0e07\u0e40\u0e14\u0e35\u0e22\u0e27\u0e02\u0e2d\u0e07\u0e42\u0e23\u0e07\u0e40\u0e23\u0e35\u0e22\u0e19\u0e19\u0e35...",
                "products_date_available":"0",
                "products_image":"10-NogizakaHarukaNoHimitsu.jpg",
                "addDate":"2010-09-30 10:20:03"
            }
Run Code Online (Sandbox Code Playgroud)

我无法循环这个Json,因为没有方法调用的密钥.getJSONArray("key")

这是我的java

JSONObject object = new JSONObject(resultValue);

    //JSONArray jsonArray = object.getJSONArray("key");
    for (int i = 0; i < jsonArray.length(); i++){
     JSONObject objJson = jsonArray.getJSONObject(i);
     int products_id = objJson.getInt("products_id");
     String products_name = objJson.getString("products_name");
     Toast.makeText(getApplicationContext(),products_name,Toast.LENGTH_SHORT).show();

                    }
Run Code Online (Sandbox Code Playgroud)

Fah*_*que 8

您的结果包含JSONArray两个索引(0,1).运行循环两次或JSONArray的大小.获取密钥的价值products_id.

JSONArray array = new JSONArray(yourStringData);
for(int i = 0; i<array.length() ; i++){
   String productInfo = array.get(i);

   JSONObject object = new JSONObject(productInfo );
   String myRequiredData = object.get("products_id");
 }
Run Code Online (Sandbox Code Playgroud)