【问题标题】:How to convert JSONArray to ListView in Android? [duplicate]如何在 Android 中将 JSONArray 转换为 ListView? [复制]
【发布时间】:2021-06-20 23:38:30
【问题描述】:

我的 json 是:{"success":["demo20","demo21","iostest3"],"errorCode":0}

我需要解析 json 然后在 ListView 中添加值,这是我的代码:

 ArrayList<String> items = new ArrayList<String>();
 JSONObject object = new JSONObject(result.toString());
 int errorCode = object.getInt("errorCode");
 if (errorCode == 0){
     JSONArray array = object.getJSONArray("success"); 
      for (int i = 0; i < array.length(); i++){
          ????
       }
     ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, items);
     listView.setAdapter(arrayAdapter);
 }

 please help me , thanks.

【问题讨论】:

    标签: android android-listview


    【解决方案1】:
    for (int i = 0; i < array.length(); i++){
          items.add(array.getString(i));
    }
    

    【讨论】:

      猜你喜欢
      • 2019-12-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-27
      • 1970-01-01
      • 2014-01-30
      • 1970-01-01
      • 2017-04-18
      相关资源
      最近更新 更多