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 7732971
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T06:51:59+00:00 2026-06-01T06:51:59+00:00

I have the following json returned to me from an API. sections: { 1:

  • 0

I have the following json returned to me from an API.

"sections": {
  "1": {
    "title":"Within 1 Km",
    "count":6
  },
  "3": {
    "title":"Within 3 Km",
    "count":1
  },
  ....and some more here

It’s worth nothing this is not a JSON Array.

I need to iterate through the objects contained with sections, but because it is not a JSON array, I’m extracting the names (“1”, “3”, and so on) and looping through the JSON selecting each object.

JSONObject jsSecs = new JSONObject(data).getJSONObject("sections");
JSONArray jsSecsArray = jsSecs.names();

What I’ve noticed is that JSONArray.names() will return an array of names out of order from the JSON.

I expected 0th element to contain “1”, 1st element to contain “3”.

What I got was 0th element to contain “10”, 2nd element to contain “1”, etc – all out of sync.

What’s going on here? Have I missed something obvious? I don’t want to reorder things if I don’t have to. It seems like more fuss than it’s worth.

  • 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-06-01T06:52:00+00:00Added an answer on June 1, 2026 at 6:52 am

    check http://www.json.org/javadoc/org/json/JSONObject.html, it clearly explains:

    A JSONObject is an unordered collection of name/value pairs.

    Means A JSONObject does not maintain order of insertion. as lists or JSONArray has.

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

Sidebar

Related Questions

I have the following JSON data being returned, but for some reason, Javascript or
I have some code that requests some JSON from an API. When data is
I have the following JSON date returned from a MVC page e.g. DateProcessed:\/Date(1258125238090)\/ and
Say I have the following JSON string returned from server: { response:{ imageInstances:{ one:{
I have the following JSON structure, being returned from an AJAX call (pseudo values)
I have the following JSON returned from an AJAX call: {rows:[{Date:07/10/2011,Value:1206,Action:Drink}, {Date:07/11/2011,Value:2288,Action:Pie}, {Date:07/12/2011,Value:1070,Action:Drink}, {Date:07/13/2011,Value:1535,Action:Beer},
I have the following JSON object being returned from my webserver. I can't figure
I have some Json being returned from facebook which I'm then parsing in to
How do I parse the following json returned from Facebook? I have tried by
I have the following json code file named: sections.json { section1: { priority: 1,

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.