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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:37:32+00:00 2026-05-23T01:37:32+00:00

Right now I’m using the org.json JSON library. JSONArray data = new JSONArray(); for

  • 0

Right now I’m using the org.json JSON library.

JSONArray data = new JSONArray();

        for (PkgLoad pkgLoad : list) {
            JSONArray row = new JSONArray();
            row.put(Double.parseDouble(df.format(pkgLoad.ounces)));
            row.put(pkgLoad.revolutions);
            data.put(row);
        }
        jsonResponse.put("aaData", data);

This is how I’m building my array. Row by row(I like doing this.) If there is a way to build the data row by row in any other libraries let me know.

Anyway. With that method I get this.

"aaData":[[2.55,6],[2.54,6],[2.53,6],[2.54,6],[2.55,6],[2.52,6],[2.55,6],[2.52,6],[2.54,6],[2.53,6]]}

That’s fine. The field names are left off. With the other libraries I get the field names. So it becomes this.

 "aaData":[["ounces" : 2.55, "revolutions" : 6], etc, etc}

How do I omit this fields. Thank you very much.

  • 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-23T01:37:33+00:00Added an answer on May 23, 2026 at 1:37 am

    So with Flexjson you wouldn’t duplicate the work you did to build your JSON from the data model (i.e. PkgLoad). If you wanted to convert that object to JSON you’d do something like the following:

    List<PkgLoad> packages = new ArrayList<PkgLoad>();
    packages.add( new PkgLoad( 24.3, 6 ) );
    packages.add( new PkgLoad( 45.3, 5 ) );
    packages.add( new PkgLoad( 23.3, 4 ) );
    ...
    String json = new JSONSerializer().serialize( packages, "aaData" );
    

    That would produce JSON like the following:

    { "aaData": [ { "ounces": 24.3, "revolutions": 6 }, { "ounces": 45.3, "revolutions": 5 }, { "ounces": 23.3, "revolutions": 4 } ] }
    

    Why? Because the list object you gave it contained an object inside it that had two fields “ounces” and “revolutions”, and that’s what you get back.

    That’s great because it’s a single line to encode your JSON without requiring you write a lot of boilerplate code to translate your object model into JSON. The thing you have to be flexible on is that your JSON output will mirror (more or less) your object model design. If you’re happy with that Flexjson, gson, and jackson then they will take care of all the mundane tasks of translating your object into JSON for you so you can get back to writing your code.

    However, if you have to have a drastically different format of JSON from your object model your best using org.json library and doing it by hand. Trying to tell these libraries how to convert your objects into something like what you posted is going to be as much work to writing it manually.

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

Sidebar

Related Questions

right now I'm creating an array and using: render :json => @comments This would
Right now, I'm particularly interested in reading the data from MP3 files (ID3 tags?),
Right now I am using the following CSS: option { border-width: 1px; border-style: solid;
Right now, I'm using this fashion: window.Foo = { alpha: function() {}, bravo: function(arg)
Right now you can sort out the list, by clicking on links that is
Right now I'm stuck between using PHP's native session management, or creating my own
Right now I have to create a new physical file in eclipse android for
Right now I am writing a little c++ console program using VS2010 Express. The
Right now, I keep all of my projects on my laptop. I'm thinking that
Right now my ant task looks like. <javadoc sourcepath=${source} destdir=${doc}> <link href=http://java.sun.com/j2se/1.5.0/docs/api/ /> </javadoc>

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.