使用 JSON 参数改造 GET 请求
Retrofit GET request with JSON parameters
我正在尝试通过改造我的自定义对象从解析服务器获取。
http 请求将是:
https://MY.SERVER./1/classes/Fiestas?where={"Epoca":{"__type":"Pointer","className":"Epocas","objectId":"myObjectId"}}
所以我有这个界面:
@GET("Fiestas?where={\"Epoca\":{\"__type\":\"Pointer\",\"className\":\"Epocas\",\"objectId\":\"{epoca_id}\"}}")
fun getFiestaByEpocaId(@Path("epoca_id") epoca_id: String): Deferred<JSONResponse>
但是我收到这个错误:
java.lang.IllegalArgumentException: URL query string "where={"Epoca":{"__type":"Pointer","className":"Epocas","objectId":"{epoca_id}"}}" must not have replace block. For dynamic query parameters use @Query.
for method FiestaApi.getFiestaByEpocaId
有人知道在 kotlin 中发送 JSON 内部 GET 改造请求的任何解决方案吗?
谢谢!
你可以试试这个:
@GET("Fiestas")
fun getFiestaByEpocaId(
@Query("where") jsonString: String
): Call<JSONObject>
您的 json 对象是:
val jsonString = "{\"__type\":\"Pointer\",\"className\":\"Epocas\",\"objectId\":\"{epoca_id}\"}}"
并在请求方法
之前调用jsonString.replace("\","")
我正在尝试通过改造我的自定义对象从解析服务器获取。
http 请求将是:
https://MY.SERVER./1/classes/Fiestas?where={"Epoca":{"__type":"Pointer","className":"Epocas","objectId":"myObjectId"}}
所以我有这个界面:
@GET("Fiestas?where={\"Epoca\":{\"__type\":\"Pointer\",\"className\":\"Epocas\",\"objectId\":\"{epoca_id}\"}}")
fun getFiestaByEpocaId(@Path("epoca_id") epoca_id: String): Deferred<JSONResponse>
但是我收到这个错误:
java.lang.IllegalArgumentException: URL query string "where={"Epoca":{"__type":"Pointer","className":"Epocas","objectId":"{epoca_id}"}}" must not have replace block. For dynamic query parameters use @Query.
for method FiestaApi.getFiestaByEpocaId
有人知道在 kotlin 中发送 JSON 内部 GET 改造请求的任何解决方案吗?
谢谢!
你可以试试这个:
@GET("Fiestas")
fun getFiestaByEpocaId(
@Query("where") jsonString: String
): Call<JSONObject>
您的 json 对象是:
val jsonString = "{\"__type\":\"Pointer\",\"className\":\"Epocas\",\"objectId\":\"{epoca_id}\"}}"
并在请求方法
之前调用jsonString.replace("\","")