0
这是我尝试使用的完整代码片段。我使用AQuery来获取json。但我有一个问题。 JsonObject,JsonObject ...始终为空。我尝试了“邮递员”的URL,它返回了我需要的JSON。问题是 1.我将JSONObject改为String,并且得到了该文件。这怎么可能。 2.我听说过Retrofit。我阅读所有的文档,但我不明白..根据谁使用改造他们说改造比AQuery更好。我如何将此代码更改为Retrofit? 3.它是AQueryproblem或我的代码的问题AQuery JSONObject null
谢谢。
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;
}
}