android - 无法使用 volley 将 JSON 值从服务器获取到 Spinner
问题描述
以下是我的 JSON 数据,但我无法使用 volley获取"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)"
}
]
解决方案
我不确定是什么错误,但我建议使用 Retrofit Library。它非常简单,整洁且性能明智,然后凌空抽射也很好。
它会自动将 json 转换为 pojo,所以我认为不需要手动获取
看看下面的例子。花一点时间在这上面,那么它对你将来会有帮助。
https://medium.com/@prakash_pun/retrofit-a-simple-android-tutorial-48437e4e5a23
推荐阅读
- javascript - 如何使用 document.createElement 从 React 设置 onClick?
- ruby - 循环遍历未知级别的嵌套对象的 DRY 策略
- javascript - 使用 Angular 在 Highcharts 中绘制的数据自己乘以 1000
- swiftui - 未触发 modalView 更改中的 ContentView 重绘
- c++ - 如何在 SFML/C++ 中设置与旋转形状的碰撞
- swiftui - 如何在将相机作为父 SwiftUI 的滚动视图顶部应用不透明度
- c - 使用指针和函数来存储和检索数据的结构
- sql - 根据 SQL Server 中的某些列删除重复记录
- javascript - 带有样式化组件的 Redux 表单
- vega-lite - Vega Lite:带有更多刻度线的符号刻度