使用google api将xml提供给json

时间:2015-03-10 21:54:20

标签: android json google-api feed

我正在使用google api将feed xml转换为json,但是当我在我的Android应用程序上使用它时,它说" 03-10 22:32:08.045:E / log_tag(1456):解析数据时出错org.json.JSONException:类型java.lang.String的值无法转换为JSONObject",这是我的代码的一部分,我将xml转换为json,有人可以帮助我吗?感谢。

private class DownloadJSON extends AsyncTask<Void, Void, Void> {

                @Override
                protected void onPreExecute() {
                    super.onPreExecute();
                    // Create a progressdialog
                    mProgressDialog = new ProgressDialog(NoticiasMia.this);
                    // Set progressdialog title
                    //mProgressDialog.setTitle("Android JSON Parse Tutorial");
                    // Set progressdialog message
                    mProgressDialog.setMessage("Actualizando...");
                    mProgressDialog.setIndeterminate(false);
                    // Show progressdialog
                    mProgressDialog.show();
                }

                @Override
                protected Void doInBackground(Void... params) {
                    // Create an array
                    arraylist = new ArrayList<HashMap<String, String>>();
                    // Retrieve JSON Objects from the given URL address
                    jsonobject = JSONfunctions
                            .getJSONfromURL("http://ajax.googleapis.com/ajax/services/feed/load?v=1.0&num=10&q=myfeedurl");

                    try {
                        // Locate the array name in JSON
                        if(jsonobject == null) 
                            return null; 

                        JSONObject subObjuno = jsonobject.getJSONObject("responseData");
                        JSONObject subObjdos = subObjuno.getJSONObject("feed");

                        jsonarray = subObjdos.getJSONArray("entries");

                        for (int i = 0; i < jsonarray.length(); i++) {
                            HashMap<String, String> map = new HashMap<String, String>();
                            jsonobjecttres = jsonarray.getJSONObject(i);
                            // Retrive JSON Objects


                            map.put("title", jsonobjecttres.getString("title"));
                            map.put("link", jsonobjecttres.getString("link"));
                            map.put("publishedDate", jsonobjecttres.getString("publishedDate"));
                            map.put("contentSnippet", jsonobjecttres.getString("contentSnippet"));



                            arraylist.add(map);
                        }
                    } catch (JSONException e) {
                        Log.e("Error", e.getMessage());
                        e.printStackTrace();
                    }
                    return null;
                }

                @Override
                protected void onPostExecute(Void args) {

                    if(arraylist == null || arraylist.size() == 0){
                         new DownloadJSON().execute();
                         mProgressDialog.dismiss();
                         return;
                    }
                    // Locate the listview in listview_main.xml
                    listview = (ListView) NoticiasMia.this.findViewById(R.id.lista_faltas_cometidas);
                    // Pass the results into ListViewAdapter.java
                    adapter = new LazyAdapterNoticiasMias(NoticiasMia.this, arraylist, "fonts/Roboto-Thin.ttf", "fonts/Roboto-Medium.ttf");
                    // Set the adapter to the ListView
                    listview.setAdapter(adapter);
                    // Close the progressdialog
                    mProgressDialog.dismiss();
                }
            }

0 个答案:

没有答案