Android翻新发送数组为x-www-form-urlencoded [英] android retrofit send array as x-www-form-urlencoded
本文介绍了Android翻新发送数组为x-www-form-urlencoded的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用翻新作为网络库,我想以 x-www-form-urlencoded
发送JSON数组,但是我不知道该怎么做.
I'm using retrofit as my network library, and I want to send a JSON array as x-www-form-urlencoded
, but I don't know how to do that.
这是我的请求API:
@POST("book")
@FormUrlEncoded
Call<BookTicket> BookFlight(@Header("Authorization") String authorization,
@Header("Content-Type") String content_type,
@Field("rootType") Integer rootType ,
@Field("BookingStep2") ArrayList<JSONObject> BookingStep2
);
这是一个示例请求:
{
"rootType": 1,
"BookingStep2": {
"OriginFlightSegment": {
"FlightNumber": "sample",
"Source": "sample",
"TotalTime": "sample",
"FareDatas": [
{
"PassengerType": 1,
"Endorsements": "sample",
"FareBasisCode": "sample"
},
{
"PassengerType": 1,
"Endorsements": "sample",
"FareBasisCode": "sample"
}
]
}
}
}
在改型中将JSON数组作为字段发送是正确的吗?
Is it right to send JSON array as field in retrofit?
推荐答案
要将数组对象以form-url_encoded形式发布,只需在改造中使用它即可.
To post array object as form-url_encoded just use this in retrofit.
@POST(ApiConstants.JOB_CARD_SAVE)
@FormUrlEncoded
Call<MasterResponse<JobCardSaveResponse>> jobCardSave(@FieldMap Map<String, Object> _jobCardRequest,
@Field("qty[]") List<String> qty,
@Field("service_id[]") List<String> service_id);
只需将您的数组对象放在@field中.
Just put your array object in @field.
这篇关于Android翻新发送数组为x-www-form-urlencoded的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文