0
我正在使用retrofit library.I创建了一个类,其中我从其他类中获取特定ID的值,并且我想获取该ID的特定列表,但在onResponse()
方法中出现错误。我检查了JSON格式的邮差列表正在提取......但不在这里!如何使用Retrofit库处理onResponse方法?
public class Main2Activity extends AppCompatActivity implements Callback<MailChimpEmailResponse> {
public String idReceived;
List<MailChimpEmailResponseSecond> emailList = new ArrayList<>();
private RecyclerView recyclerViewSecond;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
Call<MailChimpEmailResponse> call = MailChimpAPIClient.getClient().fetchMembers(idReceived,"efb918ee88a3a8a77-us15");
call.enqueue(this);
}
@Override
public void onResponse(Call<MailChimpEmailResponse> call, Response<MailChimpEmailResponse> response) {
Log.d("ashu", "null response");
Intent intent = getIntent();
idReceived = intent.getStringExtra("id_value");
Log.d("ashu", "id received is: " + idReceived);
MailChimpEmailResponse listResponse = response.body();
for (MailChimpEmailResponseSecond list : listResponse.emailLists) {
Log.d("ashu", list.getEmailListName());
this.emailList = listResponse.emailLists;
}
recyclerViewSecond = (RecyclerView) findViewById(R.id.my_recycler_view_second);
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
recyclerViewSecond.setLayoutManager(linearLayoutManager);
EmailAdapter adapter = new EmailAdapter(this.emailList);
recyclerViewSecond.setAdapter(adapter);
adapter.notifyDataSetChanged();
}
@Override
public void onFailure(Call<MailChimpEmailResponse> call, Throwable t) {
}
}
我的API类:
public interface MailChimpApi {
@GET("lists")
public Call<MailChimpListResponse> fetchLists(@Query("apikey") String apikey, @Query("offset") int offset, @Query("count") int count);
@GET("lists/{list_id}/members")
public Call<MailChimpEmailResponse> fetchMembers(@Path("list_id") String listId,@Query("apikey") String apikey);
}
的json:
{
"members": [
{
"id": "04d80020e78edd86a79eda",
"email_address": "[email protected]",
"unique_email_id": "784c772918",
"email_type": "html",
"status": "subscribed",
"merge_fields": {
"FNAME": "Ashsdjssh",
"LNAME": "kudjskjar"
},