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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T23:26:32+00:00 2026-05-19T23:26:32+00:00

I am trying to write inner follow by inner2 then inner3. However, right now

  • 0

I am trying to write inner follow by inner2 then inner3. However, right now it is inner2, inner3 then inner1. How can I write JSON object to go according to the sequence i want?

public void toJSON(String description, String Name)
{
    JSONObject inner = new JSONObject();
    JSONObject inner2= new JSONObject();
    JSONObject inner3= new JSONObject();

    try {   
    outer.put("DATA 1", inner);
    inner.put("description", description);  
    inner.put("filename", imageName);

    outer.put("DATA 2", inner2);    
    inner2.put("model", "modelname");

    outer.put("Datetime", inner3);
    inner3.put("Datetime", "DateTime");

    } catch (JSONException ex) {
    ex.printStackTrace();
    }
}
  • 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-19T23:26:33+00:00Added an answer on May 19, 2026 at 11:26 pm

    From the JSONObject JavaDocs:

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

    This means you can’t have custom sorting. If you do need custom sorting, wrap the individual objects in a JSONArray:

    public void toJSON(String description, String Name){
        JSONObject inner = new JSONObject();
        JSONObject inner2 = new JSONObject();
        JSONObject inner3 = new JSONObject();
        JSONArray array = new JSONArray();
    
        try{
            array.put(inner);
            inner.put("description", description);
            inner.put("filename", imageName);
    
            array.put(inner2);
            inner2.put("model", "modelname");
    
            array.put(inner3);
            inner3.put("Datetime", "DateTime");
    
            outer.put("values", array);
    
        } catch(JSONException ex){
            ex.printStackTrace();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to write a single Linq Query that can concat inner collections of
Trying to write a chat, like on facebook, I wondered if two clients can
Trying to write a function to see how often an object exists and give
I'm trying to write the following query in LINQ, but can't seem to get
I was trying to write a query with inner join only if RepID of
I'm trying to write a notification script using python-dbus. How can I get properties
I'm trying to write an HQL query to select objects which contain an object
I'm trying to write some javascript that will grab the inner text of li
I'm trying to write an INNER JOIN query. I wanted to get rows/information that
I'm trying write a query to find records which don't have a matching record

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.