我需要使用URL编码

我需要使用URL编码

本文介绍了如何使用模型的改造字符串和数组列表发送PUT请求,我需要使用URL编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以指导我如何使用此json发送PUT请求

can anyone guide me how to send PUT request with this json

 {
  "delivery_status": "Partially Completed",
  "signatures": "==skdjfkjdsakjhfoiuewyrdskjhfjdsaf",
  "assignee_note": "this is remarks and and and nothing",
  "id": "this is remarks and and and nothing",
  "returned_products": [
    {
      "id": "18",
      "quantity": 3,
      "reasons": "i dont know reason .. bus wapis a gya saman :-)"
    },
    {
      "id": "19",
      "quantity": 4,
      "reasons": "i dont know reason .. bus wapis a gya saman :-)"
    }
  ]
}

这是我尝试过但失败的

@FormUrlEncoded
    @PUT("delivery_notes/update/1.json")
    Call<UploadDeliveryNote> postDeliveryNote(
            @Field("returned_products[]") ArrayList<ReturnedProduct> returned_products,
            @Field("delivery_status") String deliveryStatus,
            @Field("signatures") String signatures,
            @Field("id") String id,
            @Field("assignee_note") String note
    );

但是失败了,然后尝试了这个.

but failed then tried this.

@Headers("Content-Type: application/json")
    @PUT("delivery_notes/update/1.json")
    Call<UploadDeliveryNote> postDeliveryNote(@Body String body);

我在这方面做错了什么?我的主要问题是我正在发送简单的字符串,并且模型的一个对象是返回的模型的列表预先感谢.

what am i doing wrong in this?my main problem is i am sending simple strings and one object of model is a list of models returned_productsThanks in advance.

推荐答案

可以通过Retrofit实现此调用的方法有很多,我认为最简单的方法就是制作模型类.

There can be many ways to implement this call via Retrofit, the most easy I can think is to make model classes.

您的通话看起来像-

@PUT(""delivery_notes/update/1.json"")
Call<ApiResponse<UploadDeliveryNote>> postDeliveryNote(@Body Example example);

并称呼它

    Example example = new Example();
    example.setAssigneeNote();
    example.setDeliveryStatus();
    example.setReturnedProducts();
    apiInterface.postDeliveryNote(example);

Example.java

public class Example {

    @SerializedName("delivery_status")
    @Expose
    private String deliveryStatus;
    @SerializedName("signatures")
    @Expose
    private String signatures;
    @SerializedName("assignee_note")
    @Expose
    private String assigneeNote;
    @SerializedName("id")
    @Expose
    private String id;
    @SerializedName("returned_products")
    @Expose
    private List<ReturnedProduct> returnedProducts = null;

    public String getDeliveryStatus() {
        return deliveryStatus;
    }

    public void setDeliveryStatus(String deliveryStatus) {
        this.deliveryStatus = deliveryStatus;
    }

    public String getSignatures() {
        return signatures;
    }

    public void setSignatures(String signatures) {
        this.signatures = signatures;
    }

    public String getAssigneeNote() {
        return assigneeNote;
    }

    public void setAssigneeNote(String assigneeNote) {
        this.assigneeNote = assigneeNote;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public List<ReturnedProduct> getReturnedProducts() {
        return returnedProducts;
    }

    public void setReturnedProducts(List<ReturnedProduct> returnedProducts) {
        this.returnedProducts = returnedProducts;
    }

}

ReturnedProduct.java

public class ReturnedProduct {

    @SerializedName("id")
    @Expose
    private String id;
    @SerializedName("quantity")
    @Expose
    private int quantity;
    @SerializedName("reasons")
    @Expose
    private String reasons;

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public int getQuantity() {
        return quantity;
    }

    public void setQuantity(int quantity) {
        this.quantity = quantity;
    }

    public String getReasons() {
        return reasons;
    }

    public void setReasons(String reasons) {
        this.reasons = reasons;
    }

}

这篇关于如何使用模型的改造字符串和数组列表发送PUT请求,我需要使用URL编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 17:15