无法使用齐射将JSON值从服务器获取到Spinner中

时间:2018-08-06 14:24:55

标签: android

以下是我的JSON数据,但是我无法使用凌空将"state"的值提取到Spinner中。

    [
    {
        "state_id": "1",
        "state": "Andaman and Nicobar (AN)"
    },
    {
        "state_id": "2",
        "state": "Andhra Pradesh (AP)"
    },
    {
        "state_id": "3",
        "state": "Arunachal Pradesh (AR)"
    },
    {
        "state_id": "4",
        "state": "Assam (AS)"
    },
    {
        "state_id": "5",
        "state": "Bihar (BR)"
    },
    {
        "state_id": "6",
        "state": "Chandigarh (CH)"
    },
    {
        "state_id": "7",
        "state": "Chhattisgarh (CG)"
    },
    {
        "state_id": "8",
        "state": "Dadra and Nagar Haveli (DN)"
    },
    {
        "state_id": "9",
        "state": "Daman and Diu (DD)"
    },
    {
        "state_id": "10",
        "state": "Delhi (DL)"
    },
    {
        "state_id": "11",
        "state": "Goa (GA)"
    },
    {
        "state_id": "12",
        "state": "Gujarat (GJ)"
    },
    {
        "state_id": "13",
        "state": "Haryana (HR)"
    },
    {
        "state_id": "14",
        "state": "Himachal Pradesh (HP)"
    },
    {
        "state_id": "15",
        "state": "Jammu and Kashmir (JK)"
    },
    {
        "state_id": "16",
        "state": "Jharkhand (JH)"
    },
    {
        "state_id": "17",
        "state": "Karnataka (KA)"
    },
    {
        "state_id": "18",
        "state": "Kerala (KL)"
    },
    {
        "state_id": "19",
        "state": "Lakshdweep (LD)"
    },
    {
        "state_id": "20",
        "state": "Madhya Pradesh (MP)"
    },
    {
        "state_id": "21",
        "state": "Maharashtra (MH)"
    },
    {
        "state_id": "22",
        "state": "Manipur (MN)"
    },
    {
        "state_id": "23",
        "state": "Meghalaya (ML)"
    },
    {
        "state_id": "24",
        "state": "Mizoram (MZ)"
    },
    {
        "state_id": "25",
        "state": "Nagaland (NL)"
    },
    {
        "state_id": "26",
        "state": "Odisha (OD)"
    },
    {
        "state_id": "27",
        "state": "Puducherry (PY)"
    },
    {
        "state_id": "28",
        "state": "Punjab (PB)"
    },
    {
        "state_id": "29",
        "state": "Rajasthan (RJ)"
    },
    {
        "state_id": "30",
        "state": "Sikkim (SK)"
    },
    {
        "state_id": "31",
        "state": "Tamil Nadu (TN)"
    },
    {
        "state_id": "32",
        "state": "Tripura (TR)"
    },
    {
        "state_id": "33",
        "state": "Uttar Pradesh (UP)"
    },
    {
        "state_id": "34",
        "state": "Uttarakhand (UK)"
    },
    {
        "state_id": "35",
        "state": "West Bengal (WB)"
    }
]

1 个答案:

答案 0 :(得分:0)

我不确定出现什么错误,但是我建议使用Retrofit库。它非常简单,整洁,性能出色,而且还凌空抽射。

它会自动将json转换为pojo,所以我认为不需要手动获取

看下面的例子。花很少的时间在此上,那么将来会对您有帮助。

https://medium.com/@prakash_pun/retrofit-a-simple-android-tutorial-48437e4e5a23