Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7594515
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T21:26:08+00:00 2026-05-30T21:26:08+00:00

I have been trying to parse Json into A ListView but when i do

  • 0

I have been trying to parse Json into A ListView but when i do so I get;

03-04 14:43:45.345: E/log_tag(16519): Error parsing data org.json.JSONException: No value for items

It somehow can’t get the items out of the Json Object.

Here’s my code i used for it;

getJSON.java

  import java.io.BufferedReader;
    import java.io.InputStream;
    import java.io.InputStreamReader;

    import org.apache.http.HttpEntity;
    import org.apache.http.HttpResponse;
    import org.apache.http.client.HttpClient;
    import org.apache.http.client.methods.HttpPost;
    import org.apache.http.impl.client.DefaultHttpClient;
    import org.json.JSONException;
    import org.json.JSONObject;

    import android.util.Log;

    public class getJSON {

        public static JSONObject getJSONfromURL(String url){
            InputStream is = null;
            String result = "";
            JSONObject jArray = null;

            //http post
            try{
                    HttpClient httpclient = new DefaultHttpClient();
                    HttpPost httppost = new HttpPost(url);
                    HttpResponse response = httpclient.execute(httppost);
                    HttpEntity entity = response.getEntity();
                    is = entity.getContent();

            }catch(Exception e){
                    Log.e("NO CONNECTION", "Error in http connection "+e.toString());
            }

          //convert response to string
            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();
                    result=sb.toString();
            }catch(Exception e){
                    Log.e("CANT CONVERT DATA", "Error converting result "+e.toString());
            }

            try{

                jArray = new JSONObject(result);            
            }catch(JSONException e){
                    Log.e("CANT READ DATA", "Error parsing data "+e.toString());
            }

            return jArray;
        }
}

and

the listview.java

@Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.listplaceholder);
        ArrayList<HashMap<String, String>> mylist = new ArrayList<HashMap<String, String>>();

        //Get the data (see above)
        JSONObject json = getJSON.getJSONfromURL("http://gdata.youtube.com/feeds/api/users/UKFDubstep/uploads?v=2&alt=jsonc");


               try{



                   final JSONArray array = json.getJSONArray("items");

                        //Loop the Array
                for(int i=0;i < array.length();i++){                        

                    HashMap<String, String> map = new HashMap<String, String>();
                    JSONObject e = array.getJSONObject(i);

                    map.put("id",  String.valueOf(i));
                    map.put("title", "" + e.getString("title"));
                    map.put("viewCount", "Views: " +  e.getString("viewCount"));
                    mylist.add(map);
            }
               }catch(JSONException e)        {
                 Log.e("log_tag", "Error parsing data "+e.toString());
               }

               ListAdapter adapter = new SimpleAdapter(this, mylist , R.layout.dubstep,
                       new String[] { "title", "viewCount" },
                       new int[] { R.id.item_title, R.id.item_subtitle });

       setListAdapter(adapter);

       final ListView lv = getListView();
       lv.setTextFilterEnabled(true);
       lv.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            @SuppressWarnings("unchecked")
            HashMap<String, String> o = (HashMap<String, String>) lv.getItemAtPosition(position);
            Toast.makeText(dubstep.this, "ID '" + o.get("id") + "' was clicked.", Toast.LENGTH_SHORT).show(); 

            }
        });

    }

I have no idea where it went wrong.

Any help?
Thanks.

EDIT: json output

03-04 15:30:29.955: I/json(19109): {"error":{"message":"Response contains no content type","errors":[{"internalReason":"Response contains no content type","domain":"GData","code":"missingContentType"}],"code":400},"apiVersion":"2.1"}

Edit json link ;http://gdata.youtube.com/feeds/api/users/UKFDubstep/uploads?v=2&alt=jsonc

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T21:26:10+00:00Added an answer on May 30, 2026 at 9:26 pm

    By looking at the JSON result (by opening your example url) I see that ‘items’ is inside another JSONObject. So I believe you need to do:

    JSONObject data = json.getJSONObject('data');
    JSONArray array = data.getJSONArray('items');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

http://pastebin.com/rXbeKqAa Hi all I have been trying to parse the above JSON into a
I have been trying to get around this error for a day now and
I have been trying for days to figure out how to parse this JSON
Im trying to append some JSON data from the last.fm API, I have been
Im trying to append some JSON data from the last.fm API, I have been
I've been trying to figure out a way of presenting data dynamically but have
I have been trying to parse Java exceptions that appear in a log for
I have been trying to find a really fast way to parse yyyy-mm-dd [hh:mm:ss]
I have been trying to parse webpages by use of the HTML DOMObject in
OK I have been trying to parse a html tag which in it contains

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.