Accessing members of items in a JSONArray with Java

后端 未结 6 1566
小蘑菇
小蘑菇 2020-11-22 16:23

I\'m just getting started with using json with java. I\'m not sure how to access string values within a JSONArray. For instance, my json looks like this:

{
         


        
6条回答
  •  粉色の甜心
    2020-11-22 16:46

    Have you tried using JSONArray.getJSONObject(int), and JSONArray.length() to create your for-loop:

    for (int i = 0; i < recs.length(); ++i) {
        JSONObject rec = recs.getJSONObject(i);
        int id = rec.getInt("id");
        String loc = rec.getString("loc");
        // ...
    }
    

提交回复
热议问题