我需要从我的服务器获取一些json数据,其中包含有关公司员工协助的数据。我正在使用CalendarView
我需要更改数据来源:
Cursor cursor = context.getContentResolver()
.query(Uri.parse("content://com.android.calendar/events"),
new String[] { "calendar_id", "title", "description",
"dtstart", "dtend", "eventLocation" }, null,
null, null);
到
Cursor cursor = context.getContentResolver()
.query(Uri.parse("http://www.gettford.net/comunidad/api/calendario.php"),
new String[] { "calendar_id", "title", "description",
"dtstart", "dtend", "eventLocation" }, null,
null, null);
显然代码是错误的,但我不知道如何将json放入游标中,我知道如何获取json并将其插入数组中,但在这种情况下我不知道该怎么做。
感谢任何帮助
提前致谢。
答案 0 :(得分:0)
最后我通过改变这个来解决:
Cursor cursor = context.getContentResolver()
.query(Uri.parse("content://com.android.calendar/events"),
new String[] { "calendar_id", "title", "description",
"dtstart", "dtend", "eventLocation" }, null,
null, null);
为此:
class Asistencia extends AsyncTask<Void, Void, Void> {
@Override
protected Void doInBackground(Void... params) {
nameOfEvent.clear();
startDates.clear();
endDates.clear();
descriptions.clear();
// Retrieve JSON Objects from the given URL address
jsonobject = JSONfunctions
.getJSONfromURL("http://www.xxx.zzz");
if (jsonobject != null && jsonobject.length() > 0) {
try {
// Locate the array name in JSON
jsonarray = jsonobject.getJSONArray("datos");
for (int i = 0; i < jsonarray.length(); i++) {
jsonobject = jsonarray.getJSONObject(i);
// Retrive JSON Objects
nameOfEvent.add(jsonobject.getString("title"));
startDates.add(jsonobject.getString("dtstart"));
endDates.add(jsonobject.getString("dtend"));
}
} catch (JSONException e) {
Log.e("Error", e.getMessage());
e.printStackTrace();
}
} else {
// errores = "conexion";
}
return null;
}
@Override
protected void onPostExecute(Void args) {
}
}