我想从频道中的字段中获取数据,并使用翻新功能与android对话,我已经尝试过,但是代码不起作用,这是我的端点
Retrofit retrofit=new Retrofit.Builder()
.baseUrl("https://api.thingspeak.com/")
.addConverterFactory(GsonConverterFactory.create())
.build();
API接口
@GET("channels/637542/fields/1.json?results=2")
Call<List<Ultrasonic>> getData();
POJO类
package com.iot.parkthink.parkthink.POJOClass;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
public class Ultrasonic {
@SerializedName("created_at")
@Expose
private String createdAt;
@SerializedName("entry_id")
@Expose
private Integer entryId;
@SerializedName("field1")
@Expose
private String field1;
private String image;
public String getImage() {
return image;
}
public String getCreatedAt() {
return createdAt;
}
public void setCreatedAt(String createdAt) {
this.createdAt = createdAt;
}
public Integer getEntryId() {
return entryId;
}
public void setEntryId(Integer entryId) {
this.entryId = entryId;
}
public String getField1() {
return field1;
}
public void setField1(String field1) {
this.field1 = field1;
}
}
答案 0 :(得分:1)
代替
@GET("channels/637542/fields/1.json?results=2")
Call<List<Ultrasonic>> getData();
您可以使用
@GET("channels/637542/fields/1.json")
Call<List<Ultrasonic>> getData(@Query("results") int results);
并调用它
getData(2)