Android 无法为类创建@Body转换器
当我调用post-api时,我试图使用改型来调用它 无法为类CreateOrderRequest创建@Body转换器(参数#1) 对于方法CheckOutService.createOrderAndroid 无法为类创建@Body转换器,android,kotlin,retrofit2,Android,Kotlin,Retrofit2,当我调用post-api时,我试图使用改型来调用它 无法为类CreateOrderRequest创建@Body转换器(参数#1) 对于方法CheckOutService.createOrder @WorkerThread suspend fun createOrderService(body: CreateOrderRequest) { if (networkAvailable()) { val retrofit = Retrofit
@WorkerThread
suspend fun createOrderService(body: CreateOrderRequest) {
if (networkAvailable()) {
val retrofit = Retrofit
.Builder()
.baseUrl(BASE_URL)
.addConverterFactory(MoshiConverterFactory.create())
.build()
val service = retrofit.create(CheckOutService::class.java)
service.createOrder(body)
}
}
模型
data class CreateOrderRequest(
val cardItem: ArrayList<JSONObject>,
val deliveryCost: String,
val deliveryTime: String,
val lat: String,
val long: String,
val name: String,
val note: String,
val paymentMethod: String,
val phone: String,
val status: String,
val subTotal: String,
val timeStamp: JSONObject,
val total: String
)
data class CardItem(
val categoryID: String,
val detailes: String,
val hasDiscount: Boolean,
val image: String,
val inStock: Boolean,
val name: String,
val oldPrice: String,
val price: String,
val productID: String,
val qty: String,
val variant: String,
val subCategoryID: String,
val subSubCategoryID: String
)
我有完全相同的问题,你能找到解决方案吗?我有完全相同的问题,你能找到解决方案吗?
interface CheckOutService {
@POST("createOrder")
suspend fun createOrder(@Body user: CreateOrderRequest)
}