我对使用Android和Android网络很陌生,但遇到了麻烦。这是我的代码:
private void getParticipantsForMeeting(Integer id)
{
AndroidNetworking.get(LOCALHOST + "/meeting?meetingId={meetingid}")
.addPathParameter("meetingid", String.valueOf(meeting.getId()))
.setTag(this)
.setPriority(Priority.LOW)
.build()
.getAsObjectList(User.class, new ParsedRequestListener<List<User>>() {
@Override
public void onResponse(List<User> response) {
if (response == null)
Log.println(Log.INFO, "GETMEETINGPARTICIPANTS", "No participants found for this meeting");
else {
meeting.setParticipants(response);
Log.println(Log.INFO, "GETMEETINGPARTICIPANTS", "No participants found for this meeting");
}
}
@Override
public void onError(ANError anError) {
Log.println(Log.ERROR, "GETMEETINGPARTICIPANTS", "Error while trying to get participants for meeting");
}
});
}
when I am in onResponse()
method, I get the requested response, but after parsing the method, meeting.getParticipants()
is still null. I don't understand what I'm doing wrong, because other calls are working as expected, except this one. I can't figure out this strange behavior, I have also tried to add the response in a list and return the list, save it as SharedPreferences
and save it in a static variable, but the problem is still here. Maybe a relevant mention is that issue happens in a fragment and the other calls didn't return a list of objects, but only one object.
Could someone please explain me why I get this error and how can I fix it? You would really help a puddled student!
假设您与Json合作。那是你的问题。 “其他调用不返回对象列表,而仅返回一个对象。”您需要使用jsonarray,然后遍历数组并解析对象。 看这里,