Android解析json空
我试图解析json,但结果是空的。如果有人知道帮助我,我做错了什么 谢谢 这是我的密码Android解析json空,android,json,Android,Json,我试图解析json,但结果是空的。如果有人知道帮助我,我做错了什么 谢谢 这是我的密码 public class GetJSON extends AsyncTask<Void, Void, Void> { @Override protected Void doInBackground(Void... params) { // Running in background try { httpclient = new Default
public class GetJSON extends AsyncTask<Void, Void, Void> {
@Override
protected Void doInBackground(Void... params) { // Running in background
try {
httpclient = new DefaultHttpClient(new BasicHttpParams());
HttpPost httppost = new HttpPost(
"************");
// Depends on your web service
httppost.setHeader("Content-type", "application/json");
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
inputStream = entity.getContent();
// json is UTF-8 by default
BufferedReader reader = new BufferedReader(
new InputStreamReader(inputStream, "UTF-8"), 8);
sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
result = sb.toString();
Log.i("Jsonnnnnnnnnnnnn", result);
}
catch (Exception squish) {
}
return null;
}
@Override
protected void onPreExecute() { // Activity is on progress
}
@Override
protected void onPostExecute(Void v) {
try {
jsonArray = new JSONArray(result);
date = new String[jsonArray.length()];
// quote = new String[jsonArray .length()];
// by = new String[jsonArray.length()];
for (int i = 0; i < jsonArray .length(); i++) {
jsonObj = (JSONObject) jsonArray .get(i);
date[i] = jsonObj.getString("title");
// quote[i] = jsonObj.getString("Quote");
// by[i] = jsonObj.getString("By");
} // End the for loop
remoteViews.setTextViewText(R.id.widgetdesc, date[0]);
manager.updateAppWidget(thiswidget, remoteViews);
// remoteViews.setTextViewText(R.id.tvParkStatus, quote[0]);
} catch (JSONException e) {
e.printStackTrace();
Log.e("Erorrrrrrrrrrrr", e.toString());
}
}
}
及
在我的代码中,我接收了结果字符串中的所有json数组,但我无法解析我的json结果是JSONObject而不是JSONArray。您的解析应该像这样开始:
JSONObject jsonObject = new JSONObject(result);
JSONArray jsonArray = jsonObject.getJSONArray("data");
您的数据jsonArray位于jsonObject的内部
JSONObject jsonobject = new JSONObject(result);
jsonArray= jsonobject.getJSONArray("data");
把JSON放在问题中,不要只是链接。链接腐烂。