【发布时间】:2019-07-31 10:55:15
【问题描述】:
根据我的最后一个问题: Creating Json file with C# of mysql data 我试图从创建的 JSON url/文件中获取数据,但它只是不加载请求的页面,并且在 android 模拟器上没有给出任何错误。 这是我的 Volley 代码:
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.studentss);
allstudents=new ArrayList<>();
student_lists=findViewById(R.id.students_listview);
postClass=new PostClass(allstudents,this);
student_lists.setAdapter(postClass);
mQueue=Volley.newRequestQueue(this);
jsonParse()
private void jsonParse(){
String url=".......WebForm1.aspx";
JsonObjectRequest request=new JsonObjectRequest(Request.Method.GET,
url, null,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
try {
JSONArray jsonArray=response.getJSONArray("Students");
for(int i=0;i<jsonArray.length();i++){
JSONObject stu =jsonArray.getJSONObject(i);
String stuName=stu.getString("firstname");
allstudents.add(stuName);
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
error.printStackTrace();
}
});
mQueue.add(request);
}
如果你能告诉我我的错,我将不胜感激。我认为问题与 android 而不是 json 有关,因为 我可以获取数据但不能显示它!
【问题讨论】:
标签: android json android-volley