这是我的数组
{
sales_schedule_name: "Visit Client",
sales_schedule_date: "2018-01-18",
sales_schedule_time: "10:30:00",
sales_schedule_address: "Sydney",
sales_schedule_description: "Sales Visit"
}
该数组来自 schedule.php
$query = "select sales_schedule_name,sales_schedule_date,sales_schedule_time,sales_schedule_address,sales_schedule_description from sales_schedule";
if ($stmt = $conn->prepare($query)) {
$stmt->execute();
$stmt->bind_result($sales_schedule_name, $sales_schedule_date, $sales_schedule_time, $sales_schedule_address, $sales_schedule_description);
$schedule = array();
while ($stmt->fetch()) {
//printf("%s, %s, %s, %s, %s\n", $sales_schedule_name, $sales_schedule_date, $sales_schedule_time, $sales_schedule_address, $sales_schedule_description);
$temp = array();
$temp['sales_schedule_name'] = $sales_schedule_name;
$temp['sales_schedule_date'] = $sales_schedule_date;
$temp['sales_schedule_time'] = $sales_schedule_time;
$temp['sales_schedule_address'] = $sales_schedule_address;
$temp['sales_schedule_description'] = $sales_schedule_description;
array_push($schedule, $temp);
}
$stmt->close();
}
//displaying the result in json format
echo json_encode($schedule);
任何人都可以帮助我使用 json 在我的公共列表 getTestData() 上调用该数组吗?
公共类 ScheduleFragment 扩展片段 { 公共 ScheduleFragment() { } RecyclerView scheduleRecyclerView; @覆盖 public View onCreateView(LayoutInflater inflater, ViewGroup 容器, Bundle savedInstanceState) { 查看视图 = inflater.inflate(R.layout.fragment_schedule, container, false); getActivity().setTitle("调度任务"); scheduleRecyclerView= view.findViewById(R.id.schedule_list); 线性布局管理器线性布局管理器=新线性布局管理器(getActivity()); scheduleRecyclerView.setLayoutManager(linearLayoutManager); scheduleRecyclerView.setHasFixedSize(true); ScheduleAdapter mAdapter = new ScheduleAdapter(getActivity(), getTestData()); scheduleRecyclerView.setAdapter(mAdapter); 返回视图; } 公共列表 getTestData() { 最终列表 recentSchedule = new ArrayList(); 最近的Schedule.add(new ScheduleObject("拜访客户", "2018-01-18", "10:30","悉尼","销售拜访")); 返回最近的时间表; } }
我试着改变
public List<ScheduleObject> getTestData() {
//recentSchedule.add(new ScheduleObject("Visit Client", "11/10/18", "10:30","Sydney","Sales Visit"));
RequestQueue rq = Volley.newRequestQueue(getActivity().getApplicationContext());
String url= AppConfig.URL_SCHEDULELIST;
StringRequest stringRequest = new StringRequest(Request.Method.GET, url,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
// Do something with the response
try{
JSONObject o = new JSONObject(response);
JSONArray values=o.getJSONArray("salesScheduleName");
for ( int i=0; i< values.length(); i++) {
JSONObject schedules = values.getJSONObject(i);
String salesScheduleName = schedules.getString("salesScheduleName");
String salesScheduleDate = schedules.getString("salesScheduleDate");
String salesScheduleTime = schedules.getString("salesScheduleTime");
String salesScheduleAddress = schedules.getString("salesScheduleAddress");
String salesScheduleDescription = schedules.getString("salesScheduleDescription");
//Use the title and id as per your requirement
recentSchedule.add(new ScheduleObject(salesScheduleName, salesScheduleDate, salesScheduleTime, salesScheduleAddress, salesScheduleDescription));
}
} catch (JSONException ex){}
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
// Handle error
}
});
return recentSchedule;
}
但什么也没有发生