大佬教程收集整理的这篇文章主要介绍了android – org.json.jsonarray无法转换为jsonobject错误,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
在任何人的情况下更新的代码都需要这个的固定.
我的错误:
01-14 22:18:08.165: E/JSON Response:(419): > { "event":[ 01-14 22:18:08.165: E/JSON Response:(419): { 01-14 22:18:08.165: E/JSON Response:(419): "event_name":"Test Event",01-14 22:18:08.165: E/JSON Response:(419): "event_time":"7:00pm",01-14 22:18:08.165: E/JSON Response:(419): "event_price":"$15.00" 01-14 22:18:08.165: E/JSON Response:(419): } 01-14 22:18:08.165: E/JSON Response:(419): ] 01-14 22:18:08.165: E/JSON Response:(419): } 01-14 22:18:08.175: E/Json Error(419): Error: org.json.JSONException: Value [{"event_price":"$15.00","event_time":"7:00pm","event_name":"Test Event"}] at event of type org.json.JSONArray cAnnot be converted to JSONObject@H_382_5@mainActivity.java
package com.example.dba; import org.json.JSONException; import org.json.JSONObject; import android.app.Activity; import android.content.Intent; import android.os.AsyncTask; import android.os.bundle; import android.util.Log; public class MainActivity extends Activity { String event_name,event_time,event_price; static JSONObject object =null; @Override protected void onCreate(Bundle savedInstanceStatE) { super.onCreate(savedInstanceStatE); setContentView(R.layout.activity_main); new PrefetchData().execute(); } /** * Async Task to make http call */ private class PrefetchData extends AsyncTask<Void,Void,Void> { @Override protected void onPreExecute() { super.onPreExecute(); } @Override protected Void doInBACkground(Void... arg0) { JsonParser jsonParser = new JsonParser(); String json = jsonParser.getJSONFromUrl("http://www.website/test.json"); Log.e("JSON Response: ","> " + json); if (json != null) { try { JSONObject parent = new JSONObject(json); JSONArray eventDetails = parent.getJSONArray("event"); for(int i=0; i < eventDetails.length(); i++) { object = eventDetails.getJSONObject(i); event_name = object.getString("event_name"); event_time = object.getString("event_time"); event_price = object.getString("event_price"); Log.e("JSON","> " + event_name + event_time + event_price ); } } catch (JSONException E) { Log.e("Json Error","Error: " + e.toString()); e.printStackTrace(); } } return null; } @Override protected void onPostExecute(Void result) { super.onPostExecute(result); Intent i = new Intent(MainActivity.this,Events.class); i.putExtra("event_name",event_name); i.putExtra("event_time",event_timE); i.putExtra("event_price",event_pricE); startActivity(i); // close this activity finish(); } } } }
以上是大佬教程为你收集整理的android – org.json.jsonarray无法转换为jsonobject错误全部内容,希望文章能够帮你解决android – org.json.jsonarray无法转换为jsonobject错误所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。