首页 > 解决方案 > 在 Java AndroidStudio 中读取数组的 JSON 文件

问题描述

我正在尝试从 AndroidStudio 中的 JSON 文件中读取数据,格式如下:

{
"records": [
    [1,"name1","1,9"],
    [2,"name2","0,74"],
    ...
]}

我想要包含 int、String、String 的对象(每行的新对象)。有人知道怎么写吗?

标签: javaandroidjson

解决方案


这可能会有所帮助

JSONObject jsonObject ;// your json body 
    try {
        JSONArray jsonArray = jsonObject.getJSONArray("records");
        for (int i = 0; i < jsonArray.length(); i++) {
            JSONArray jArray = jsonArray.getJSONArray(i);// for each row in records([2,"name2","0,74"])
        }

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

推荐阅读