【问题标题】:Populate Custom Calendar with json data使用 json 数据填充自定义日历
【发布时间】:2014-05-20 08:30:33
【问题描述】:

我需要从我的服务器获取一些 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 并将其插入到数组中,但在这种情况下我不知道该怎么做。

感谢任何帮助

提前致谢。

【问题讨论】:

  • Obviously the code is wrong... 为什么?似乎是什么问题?你有错误吗?

标签: android json android-calendar android-cursor android-json


【解决方案1】:

最后我通过改变这个解决了:

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) {

        }

    }

【讨论】:

    猜你喜欢
    • 2019-02-16
    • 1970-01-01
    • 2023-01-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多