[英]how to access jsonarray using retrofit
how to access districtID(key)
value and name(key)
value using retrofit
? 如何使用retrofit
访问districtID(key)
值和name(key)
值?
this is json file... 这是json文件...
{
"error": false,
"message": "District successfully fetched.",
"districts": [
{
"districtID": "DIS260920181",
"name": "Raipur"
},
{
"districtID": "DIS260920182",
"name": "Bilaspur"
},
{
"districtID": "DIS011020186",
"name": "korba"
},
{
"districtID": "DIS011020187",
"name": "jagdalpur"
},
{
"districtID": "DIS021020188",
"name": "surguja"
},
{
"districtID": "DIS021020189",
"name": "Mungeli"
}
]
}
Please help :( 请帮忙 :(
将JSON数组转换为POJO类,然后使用改造网络调用来调用api。
copy your json and it gives you two model class you should put the parent class which contains error , message and districts as your output in your request. 复制您的json,它会为您提供两个模型类,您应该将包含error,message和districts的父类作为您的请求中的输出。 something like this 像这样的东西
@GET("your_url")
Call<ModelExample> nameOfMethod();
And then you have list of districts. 然后,您将获得地区列表。 you can access to the items and districtID and name I hope it helps you :) 您可以访问项目以及districtID和名称,希望对您有所帮助:)
for onResponse:
--------------------------
Call<ModalClass> daoCall = api.getconnectdata();
modelclass.enqueue(new Callback<ModalClass>() {
@Override
public void onResponse(Call<ModalClass> call, Response<ModalClass>
response) {
if(response.isSuccessful()){
modelclass= response.body();
List<Districts> list = modelclass.getAddData().getData();
adapter = new CustomListAdapter(getApplicationContext(),list);
listView.setAdapter(adapter);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.