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

  • Home
  • SEARCH
  • 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 3951782
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T01:46:18+00:00 2026-05-20T01:46:18+00:00

Hy! I have a JSON Array with the tv channels and the lenght of

  • 0

Hy!

I have a JSON Array with the tv channels and the lenght of the array is three, but after transmitting into a treemap the Value is only one.

Please Help

Code:

try
            {

                JSONObject menuobj = this.getJSONObject("responseData");
                Log.e("XXX", menuobj.toString());
                JSONArray array = menuobj.getJSONArray("countries");
                TreeMap<String, Integer> map = new TreeMap<String, Integer>();
                for (int i = 0; i < array.length(); i++)
                {
                    JSONObject obj = new JSONObject();
                    obj = array.getJSONObject(i);
                    if (obj.getString("name").equals(country))
                    {
                        Log.e("XXX2", obj.toString());
                        JSONArray arr = obj.getJSONArray("channels");
                        Log.e("XXX3", String.valueOf(arr.length()));
                        for (int j = 0; j < arr.length(); j++)
                        {
                            JSONObject obj2 = new JSONObject();
                            obj2 = arr.getJSONObject(i);
                            map.put(obj2.getString("name"), obj2.getInt("id"));
                        }
                        Log.e("XXX4", String.valueOf(map.size()));
                        return map;
                    }


                }

LogCat:

02-01 18:24:20.277: ERROR/XXX(3784): {"countries":[{"id":"1","channels":[{"id":"3","name":"ARD"},{"id":"1","name":"ORF 1"},{"id":"2","name":"ORF 2"}],"name":"Ã?sterreich"},{"id":"2","channels":[{"id":"3","name":"ARD"}],"name":"Deutschland"}]}
02-01 18:24:20.288: ERROR/XXX2(3784): {"id":"1","channels":[{"id":"3","name":"ARD"},{"id":"1","name":"ORF 1"},{"id":"2","name":"ORF 2"}],"name":"Ã?sterreich"}
02-01 18:24:20.297: ERROR/XXX3(3784): 3
02-01 18:24:20.307: ERROR/XXX4(3784): 1
  • 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-20T01:46:19+00:00Added an answer on May 20, 2026 at 1:46 am

    I believe :

    obj2 = arr.getJSONObject(i);
    

    should be

    obj2 = arr.getJSONObject(j);
    

    So you are putting three times the same object pair of key/value to the map.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have json array with a value that needs to be populated into an
I have JSON array created having code like user_images.push({'href' : value.href, 'title' : value.title
I have a json array with the key 'BASIS-TYPE'. If I use this value
My problem: I have an JSON Array containing arrays, which i render into the
I have a json array in my Particles controller that looks like this after
i have a json array that i want to convert into a plain javascript
I have a JSON array(?) of pairs of every state and a value associated
I have a JSON array with ActiveRecord objects. These objects can be reconstructed using
I have a JSON array like this: { forum:[ { id:1, created:2010-03-19 , updated:2010-03-19
I have a JSON array like below: var jsonArray = [{k1:v1},{k2:v2},{k3:v3},{k4:v4},{k5:v5}] I don't know

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.