1

我正在向 WCF Windows 服务请求一个对象数组,这些对象包含 DateTime 类型。当我的 Android 应用程序尝试从 JSONObject 消息中的对象读取数据时,如下所示:

视窗日志:

11/6/2014 1:42:00 PM

日食日志

Unparseable date: "/Date(1415205000000-0200)/" (at offset 0)

安卓请求方法

private void GetEventos(String url)
{
    showProgressDialog();
    JsonArrayRequest req = new 
            JsonArrayRequest(url, new Response.Listener<JSONArray>() {

                @Override
                public void onResponse(JSONArray response){
                    Log.d(TAG, String.valueOf(response.length()));


                    try
                    {                           
                        Evento evento;

                        for (int i = 0; i < response.length(); i++) 
                        {
                            JSONObject jsonobject = response.getJSONObject(i);                              

                            evento = new Evento();              
                            evento.setId(jsonobject.getInt("Id"));
                            evento.setNome(jsonobject.getString("Nome"));
                            evento.setIdMonitorado(jsonobject.getInt("IdMonitorado"));

                            //Test
                            SimpleDateFormat dt = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
                            Date date = dt.parse(jsonobject.getString("DataHora"));
                            Log.d(TAG, "DATA: " + date);

                            //evento.setDataHora(DateTime.parse(jsonobject.getJSONObject("DataHora")));
                            evento.setDuracao(jsonobject.getInt("Duracao"));
                            evento.setLatitudeDoLocal(Float.parseFloat(jsonobject.getString("LatitudeDoLocal")));
                            evento.setLongitudeDoLocal(Float.parseFloat(jsonobject.getString("LongitudeDoLocal")));
                            evento.setReceberNotificacao(jsonobject.getBoolean("ReceberNotificacao"));
                            evento.setNomeCidade(jsonobject.getString("NomeCidade"));
                            evento.setNomeUF(jsonobject.getString("NomeUF"));

                            _dataSoruceEvento.add(evento);

                            Log.d(TAG, evento.getDataHora().toString());
                        }

                    }catch(Exception ex){
                        Log.d(TAG, ex.getMessage().isEmpty() ? "Exception Null" : ex.getMessage());
                    }

                    hideProgressDialog();

                    //DataBindMonitorados(_dataSourceMonitorados);

                }
            }, new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    VolleyLog.d(TAG, "Error: " + error.getMessage());
                    hideProgressDialog();
                }
            });

    // Adding request to request queue
    AppController.getInstance().addToRequestQueue(req, tag_json_arry);
}

我在浏览器中执行请求时的结果

查看浏览器结果

4

1 回答 1

0

您正在/Date(1415205000000-0200)/JSON 中获取值,并且您正在尝试将其解析为"yyyy-MM-dd hh:mm:ss"

于 2014-11-07T16:29:11.693 回答