我有来自我的android的列表整数数据,我要发布以将其插入到数据库中。我使用Codeigniter Rest Controller作为API。并改造以发布我的列表整数数据。如果仅发布单个数据,但如何发布数据列表,“我的帖子”是否有效?请帮助我,谢谢。
Api接口
@POST("Testpage/tesarray2")
Call<PostPutDelKontak> postArray(@Body ReviewBody body);
Pojo
public class ReviewBody {
public Review review;
public ReviewBody(List<Integer> produk_id) {
review = new Review(produk_id);
}
public class Review {
@SerializedName("produk_id")
public List<Integer> produk_id;
public Review(List<Integer> produk_id) {
this.produk_id = produk_id;
}
}
列出整数发布活动
for (int i = 0; i < data.size(); i++) {
ArrayList<Object> row = data.get(i);
ProdukId.add(Integer.parseInt(row.get(1).toString()));
}
ReviewBody reviewBody = new ReviewBody(ProdukId);
Call<PostPutDelKontak> postPutDelKontakCall = mApiInterface.postArray(reviewBody);
postPutDelKontakCall.enqueue(new Callback<PostPutDelKontak>() {
@Override
public void onResponse(Call<PostPutDelKontak> call,
Response<PostPutDelKontak> response) {
Toast.makeText(CheckoutActivity.this, "Sukses",
Toast.LENGTH_SHORT).show();
}
@Override
public void onFailure(Call<PostPutDelKontak> call, Throwable t) {
Toast.makeText(CheckoutActivity.this, "Error",
Toast.LENGTH_SHORT).show();
}
});
CodeIgniter API
public function tesarray2_post()
{
$produk_id = $this->post('produk_id');
$data2 = array(
'produk_id' => $produk_id,
);
$insert = $this->db->insert('mtransaksi_detail', $data2);
if ($insert) {
$this->response($data2, 200);
} else {
$this->response(array('status' => 'fail', 502));
}
}
答案 0 :(得分:0)
使用数组发送整数,例如[25,60,2,5,...]