无法解析的日期:仅在设备上,但不在虚拟机上

时间:2014-07-23 10:24:41

标签: android json parsing date

大家好我想尝试从RSS服务条目中解析日期,但这仅适用于虚拟机。

这是我的代码:

public static com.radmas.iyc.model.rss.Response loadRssFeedExternal(String url) {
    try {
        String url2 = "http://ajax.googleapis.com/ajax/services/feed/load?v=2.0&q=" + url + "&num=40&userip=" + getIPAddress();
        HttpRequest get = HttpRequest.get(url2).followRedirects(true);
        if (get.ok()) {
            String body = get.body();
            Gson gson = new GsonBuilder().registerTypeAdapter(Date.class, new JsonDeserializer<Date>() {
                final DateFormat df = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss Z");

                @Override
                public Date deserialize(final JsonElement json, final Type typeOfT, final JsonDeserializationContext context) {
                    try {
                        return df.parse(json.getAsString());
                    } catch (Exception e) {
                        if (BuildConfig.DEBUG) e.printStackTrace();
                        return null;
                    }

                }
            }).create();
            return gson.fromJson(body, com.radmas.iyc.model.rss.Response.class);

        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}

注意:我认为可能是GMT区域的VM是GMT +0:00而GMT上的设备+2:00可以改变设备中的设备但仍然不能正常工作。< / p>

谢谢。

编辑:字符串是我使用的RSS的RSS 2.0标准示例:

http://estaticos.marca.com/rss/portada.xml

http://futbol.as.com/rss/futbol/primera.xml

此RSS返回此日期字段Wed,23 Jul 2014 12:06:04 +0200

编辑:这里是错误的痕迹:

  

07-23 12:59:34.224 9047-9117 / com.radmas.iyc.pro.canary.debug W / System.err:java.text.ParseException:Unparseable date:&#34; Tue,2014年7月22日00:23:51 -0700&#34; (在偏移0处)   07-23 12:59:34.224 9047-9117 / com.radmas.iyc.pro.canary.debug W / System.err:at java.text.DateFormat.parse(DateFormat.java:555)   07-23 12:59:34.224 9047-9117 / com.radmas.iyc.pro.canary.debug W / System.err:at com.radmas.iyc.service.RssService $ 1.deserialize(RssService.java:74)   07-23 12:59:34.224 9047-9117 / com.radmas.iyc.pro.canary.debug W / System.err:at com.radmas.iyc.service.RssService $ 1.deserialize(RssService.java:68)   07-23 12:59:34.224 9047-9117 / com.radmas.iyc.pro.canary.debug W / System.err:at com.google.gson.TreeTypeAdapter.read(TreeTypeAdapter.java:58)   07-23 12:59:34.224 9047-9117 / com.radmas.iyc.pro.canary.debug W / System.err:at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory $ 1.read(ReflectiveTypeAdapterFactory.java:93 )   07-23 12:59:34.224 9047-9117 / com.radmas.iyc.pro.canary.debug W / System.err:at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory $ Adapter.read(ReflectiveTypeAdapterFactory.java: 172)   07-23 12:59:34.224 9047-9117 / com.radmas.iyc.pro.canary.debug W / System.err:at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.read(TypeAdapterRuntimeTypeWrapper.java:40)   07-23 12:59:34.224 9047-9117 / com.radmas.iyc.pro.canary.debug W / System.err:at com.google.gson.internal.bind.CollectionTypeAdapterFactory $ Adapter.read(CollectionTypeAdapterFactory.java: 81)   07-23 12:59:34.224 9047-9117 / com.radmas.iyc.pro.canary.debug W / System.err:at com.google.gson.internal.bind.CollectionTypeAdapterFactory $ Adapter.read(CollectionTypeAdapterFactory.java: 60)   07-23 12:59:34.224 9047-9117 / com.radmas.iyc.pro.canary.debug W / System.err:at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory $ 1.read(ReflectiveTypeAdapterFactory.java:93 )   07-23 12:59:34.224 9047-9117 / com.radmas.iyc.pro.canary.debug W / System.err:at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory $ Adapter.read(ReflectiveTypeAdapterFactory.java: 172)   07-23 12:59:34.234 9047-9117 / com.radmas.iyc.pro.canary.debug W / System.err:at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory $ 1.read(ReflectiveTypeAdapterFactory.java:93 )   07-23 12:59:34.234 9047-9117 / com.radmas.iyc.pro.canary.debug W / System.err:at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory $ Adapter.read(ReflectiveTypeAdapterFactory.java: 172)   07-23 12:59:34.234 9047-9117 / com.radmas.iyc.pro.canary.debug W / System.err:at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory $ 1.read(ReflectiveTypeAdapterFactory.java:93 )   07-23 12:59:34.234 9047-9117 / com.radmas.iyc.pro.canary.debug W / System.err:at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory $ Adapter.read(ReflectiveTypeAdapterFactory.java: 172)   07-23 12:59:34.234 9047-9117 / com.radmas.iyc.pro.canary.debug W / System.err:at com.google.gson.Gson.fromJson(Gson.java:803)   07-23 12:59:34.234 9047-9117 / com.radmas.iyc.pro.canary.debug W / System.err:at com.google.gson.Gson.fromJson(Gson.java:768)   07-23 12:59:34.234 9047-9117 / com.radmas.iyc.pro.canary.debug W / System.err:at com.google.gson.Gson.fromJson(Gson.java:717)   07-23 12:59:34.234 9047-9117 / com.radmas.iyc.pro.canary.debug W / System.err:at com.google.gson.Gson.fromJson(Gson.java:689)   07-23 12:59:34.234 9047-9117 / com.radmas.iyc.pro.canary.debug W / System.err:at com.radmas.iyc.service.RssService.loadRssFeedExternal(RssService.java:82)   07-23 12:59:34.234 9047-9117 / com.radmas.iyc.pro.canary.debug W / System.err:at com.radmas.iyc.activity.news.NewsViewActivity $ 1.doInBackground(NewsViewActivity.java:296 )   07-23 12:59:34.234 9047-9117 / com.radmas.iyc.pro.canary.debug W / System.err:at com.radmas.iyc.activity.news.NewsViewActivity $ 1.doInBackground(NewsViewActivity.java:288 )   07-23 12:59:34.234 9047-9117 / com.radmas.iyc.pro.canary.debug W / System.err:at android.os.AsyncTask $ 2.call(AsyncTask.java:288)   07-23 12:59:34.234 9047-9117 / com.radmas.iyc.pro.canary.debug W / System.err:at java.util.concurrent.FutureTask.run(FutureTask.java:237)   07-23 12:59:34.234 9047-9117 / com.radmas.iyc.pro.canary.debug W / System.err:at android.os.AsyncTask $ SerialExecutor $ 1.run(AsyncTask.java:231)   07-23 12:59:34.234 9047-9117 / com.radmas.iyc.pro.canary.debug W / System.err:at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)   07-23 12:59:34.234 9047-9117 / com.radmas.iyc.pro.canary.debug W / System.err:at java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:587)   07-23 12:59:34.234 9047-9117 / com.radmas.iyc.pro.canary.debug W / System.err:at java.lang.Thread.run(Thread.java:841)

0 个答案:

没有答案