我正在尝试从这个 URL 解析这个 JSON
如果我尝试解析这个 url
例外:
10-09 12:34:31.216: W/System.err(1856): org.json.JSONException: Value Response of type java.lang.String cannot be converted to JSONObject
10-09 12:34:31.376: W/System.err(1856): at org.json.JSON.typeMismatch(JSON.java:111)
10-09 12:34:31.391: W/System.err(1856): at org.json.JSONObject.<init>(JSONObject.java:158)
10-09 12:34:31.546: W/System.err(1856): at org.json.JSONObject.<init>(JSONObject.java:171)
10-09 12:34:31.701: W/System.err(1856): at com.example.googlecalenderevents.MainActivity2$DownloadXmlTask.doInBackground(MainActivity2.java:99)
10-09 12:34:31.854: W/System.err(1856): at com.example.googlecalenderevents.MainActivity2$DownloadXmlTask.doInBackground(MainActivity2.java:1)
10-09 12:34:32.031: W/System.err(1856): at android.os.AsyncTask$2.call(AsyncTask.java:287)
10-09 12:34:32.192: W/System.err(1856): at java.util.concurrent.FutureTask.run(FutureTask.java:234)
10-09 12:34:32.201: W/System.err(1856): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
10-09 12:34:32.363: W/System.err(1856): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
10-09 12:34:32.381: W/System.err(1856): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
10-09 12:34:32.390: W/System.err(1856): at java.lang.Thread.run(Thread.java:841)
这是我的代码:
public class MainActivity2 extends Activity {
static InputStream is = null;
String json;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
new DownloadXmlTask().execute();
}
private class DownloadXmlTask extends AsyncTask<String, Void, JSONArray> {
protected JSONArray doInBackground(String... urls) {
// Making HTTP request
try {
Log.d("doInBackground", "doInBackground");
// defaultHttpClient
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost("https://www.google.com/calendar/feeds/sjm6mdaoghv5kipc2p80jrgsc0%40group.calendar.google.com/public/basic?alt=json");
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
is = httpEntity.getContent();
}
catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
catch (ClientProtocolException e) {
e.printStackTrace();
}
catch (IOException e) {
e.printStackTrace();
}
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(is, "iso-8859-1"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
is.close();
json = sb.toString();
}
catch (Exception e) {
Log.e("Buffer Error", "Error converting result " + e.toString());
}
try {
//JSONObject jObj = new JSONObject(json);
JSONArray array=new JSONArray(json);
Log.d("ffsf","fsfs");
}
catch (JSONException e) {
e.printStackTrace();
}
return null;
}
protected void onPostExecute(JSONArray result) {
// Accessing your data
}
}
}
有人可以帮忙吗?