请说我怎样才能将所有品牌的ID全局声明为一个全局变量并将其作为参数传递给http请求?如何在全局声明json id并通过全局变量将它传递给API请求?
按照规定,我需要声明所有五个下文提及的商标为整数的品牌标识在一个单一的全局变量,并将其传递到请求,因为整数
我有形式的参数下面提供我的API响应:
{
"status": 1,
"data": [
{
"id": 1,----> brand id
"name": "AUDI",
"code": "AUDI",
"image": "",
"status": "1",
"created_at": "2016-09-27 00:07:38",
"updated_at": "2016-09-27 00:07:38"
},
{
"id": 2-----> brand id
"name": "Bravian Motor Works",
"code": "BMW",
"image": "",
"status": "1",
"created_at": "2016-09-27 00:07:58",
"updated_at": "2016-09-27 00:07:58"
},
{
"id": 3,---->brand id
"name": "AB Volvo",
"code": "VOLVO",
"image": "",
"status": "1",
"created_at": "2016-09-27 00:08:36",
"updated_at": "2016-09-27 00:08:36"
},
{
"id": 4,-----> brand id
"name": "Ford Motor Company",
"code": "FORD",
"image": "",
"status": "1",
"created_at": "2016-09-27 00:11:51",
"updated_at": "2016-09-27 00:11:51"
},
{
"id": 5,-----> brand id
"name": "Maruti Suzuki",
"code": "Maruti",
"image": "",
"status": "1",
"created_at": "2016-09-27 00:12:14",
"updated_at": "2016-09-27 00:12:14"
}
],
"msg": "success",
"info": "data list"
}
,我需要通过全局变量,如下图所示:
@Override
protected Void doInBackground(Void... arg0) {
HttpClient client = new DefaultHttpClient();
HttpPost httpPost = new HttpPost("http://garage.kaptastech.mobi/api/5k/master/vehicle");
List<NameValuePair> nameValuePair = new ArrayList<NameValuePair>(7);
nameValuePair.add(new BasicNameValuePair("user_id","5"));
nameValuePair.add(new BasicNameValuePair("registration_no", Regno));
nameValuePair.add(new BasicNameValuePair("brand","?"));
nameValuePair.add(new BasicNameValuePair("model", "5"));
nameValuePair.add(new BasicNameValuePair("type", "1"));
nameValuePair.add(new BasicNameValuePair("variant", "1"));
nameValuePair.add(new BasicNameValuePair("year", Year));
我需要将它传递的地方“ ?”
尝试将其保存在ArrayList和同时作为参数传递使用了循环 –
我试过它作为一个ArrayList。但通过它显示一个错误,数组声明不允许在这里 – Arun
你想根据特定品牌ID得到响应吗?或者你想一次获得所有品牌的回应? –