如何将json数组中的值分组以显示在列表视图中?

时间:2014-06-08 16:31:36

标签: java android json listview android-listview

如何将json数组中的值分组以显示在listview中? 这是arrayjson的例子:`

"caleg": [
            {
                "id": "jk",
                "tahun": 2014,
                "nama": "Jusuf Kalla",
                "role": "cawapres",
                "id_running_mate": "jw",
                "jenis_kelamin": "L",
                "agama": "Islam",
                "tempat_lahir": "Watampone, Sulawesi Selatan",
                "tanggal_lahir": "1942-05-15",
                "status_perkawinan": "Kawin",
                "nama_pasangan": "Hj. Mufidah Yusuf",
                "jumlah_anak": 5,
                "kelurahan_tinggal": "",
                "kecamatan_tinggal": "",
                "kab_kota_tinggal": "Jakarta Selatan",
                "provinsi_tinggal": "DKI Jakarta"}]"

我想在自定义列表视图中进行分组,如下所示: listview in detail of biograph

怎么做? 因为当我使用hashmap和arrraylist时,它不起作用..

1 个答案:

答案 0 :(得分:0)

使用Jackson使用JsonNode

ObjectMapper mapper = new ObjectMapper();

JsonNode rootNode = mapper.readTree(jsonString);

for(JsonNode node: rootNode.getElements()) {
    //add to your listview with e.g. node.getTextValue() 
}

使用

获取字段名称
rootNode.getFieldNames() 

要阅读根数组,请查看此帖子

Jackson how to transform JsonNode to ArrayNode without casting?

来源: