这是我尝试使用的片段的完整代码。我使用 AQuery 来获取 json。但我有一个问题。JsonObject,JsonObject... 总是为空。我在“邮递员”上尝试了 url,它返回了我需要的 json。问题是 1. 我将 JSONObject 更改为 String 并且我得到了文件。这怎么可能。2. 我听说过改造。我阅读了所有文档,但我无法理解..根据使用 Retrofit 的人的说法,他们说 Retrofit 比 AQuery 更好。如何将此代码更改为 Retrofit?3.是AQuery问题还是我的代码问题
谢谢你。
public class PastQuestionFragment extends Fragment {
AQuery aq = new AQuery(getActivity());
String postUrl = "http://192.168.0.21:3000/SendPastQuestion";
TextView pastQuestion;
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup
container, Bundle savedInstanceState) {
ViewGroup rootView = (ViewGroup)
inflater.inflate(R.layout.fragment_pastquestion, container, false);
pastQuestion = (TextView) rootView.findViewById(R.id.pastquestion);
aq.ajax(postUrl, JSONObject.class, new AjaxCallback<JSONObject>() {
@Override
public void callback(String url, JSONObject json, AjaxStatus status)
{
if (json != null) {
Log.d("debug", "json is not null");
try {
pastQuestion.setText(json.getString("pastquestion"));
} catch (JSONException e) {
e.printStackTrace();
}
} else {
Log.d("debug", "json is null");
}
}
});
return rootView;
}
}