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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T05:19:57+00:00 2026-05-31T05:19:57+00:00

i write some jsp to generate a json, but in one case,i meet a

  • 0

i write some jsp to generate a json, but in one case,i meet a problem,
i put order and get order are not same,
i put 1,2,3,4,5 to jsonarray, but it seem return me a wrong order 3,2,5,1,4
that is my code in jsp:

Map map = new LinkedHashMap();  
Iterator itor = listView.getList().iterator();
JSONObject json = new JSONObject();
JSONArray jArray = new JSONArray();

while ( itor.hasNext() ) {
    current = (EvidPackageDao) itor.next();
    map.put("id", current.getPackageId());
    map.put("packno", current.getPackageNo());
    map.put("photocover", current.getPhotoCover());
    map.put("photoback", current.getPhotoBack());
    map.put("evidi", current.getEvidIndentification());
    map.put("type", current.getEvidType());
    map.put("verno", current.getVersionNo());
    map.put("isbn", current.getIsbn());
    map.put("pub", current.getPublisher());
    map.put("distr", current.getDistributor());
    map.put("producer", current.getProducer());
    map.put("cprl", current.getCoptrightLogo());
    map.put("cprt", current.getCopyrightText());
    map.put("reason", current.getIllegalReason());

    Iterator it = map.entrySet().iterator();

    while (it.hasNext()) 
            {
           Map.Entry entry = (Map.Entry) it.next();
        Object key = entry.getKey();
        Object value = entry.getValue();
        System.out.println("key=" + key + ", value=" + value);

    }

            /*
             print:
        key=id, value=81
        key=packno, value=fsdfdsfsdf
        key=photocover, value=null
        key=photoback, value=null
        key=evidi, value=sdfsadf
        key=type, value=dsfsdf
        key=verno, value=sdfasdfl
        key=isbn, value=3224jsfklf
        key=pub, value=fdsjkla
        key=distr, value=lkfjl;dsfklj
        key=producer, value=fdafjdsl;
        key=cprl, value=sdfjadlfkj
        key=cprt, value=sdfadff
        key=reason, value=fdsfdsafasf

            */
    jArray.put(map);
    System.out.println(jArray.toString());
            /*
            print:
               [{"reason":null,"distr":null,"type":null,"pub":null,"verno":null,"id":82,"cprl":null,"isbn":null,"evidi":null,"photoback":null,"producer":null,"packno":null,"photocover":null,"cprt":null},{"reason":"fdsfdsafasf","distr":"lkfjl;dsfklj","type":"dsfsdf","pub":"fdsjkla","verno":"sdfasdfl","id":81,"cprl":"sdfjadlfkj","isbn":"3224jsfklf","evidi":"sdfsadf","photoback":null,"producer":"fdafjdsl;","packno":"fsdfdsfsdf","photocover":null,"cprt":"sdfadff"}]
            */

}

so how can i get the right order same with my put to the hashmap??????? like [{“id”:null, ?

  • 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-31T05:19:57+00:00Added an answer on May 31, 2026 at 5:19 am

    Which library are you using? I am using the json-simple library and the following code worked:

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Map map = new LinkedHashMap();
        JSONArray jArray = new JSONArray();
    
    
        map.put("id", "aaaaaa");
        map.put("packno", "bbbbb");
        map.put("photocover", "cccccc");
        map.put("photoback", "ddddd");
        map.put("evidi", "eeeeee");
        map.put("type", "ffffff");
    
    
        jArray.add(map);
        System.out.println(jArray.toString());
    
    }
    

    Output:

    [{"id":"aaaaaa","packno":"bbbbb","photocover":"cccccc","photoback":"ddddd","evidi":"eeeeee","type":"ffffff"}]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i write some utility class but how to get name ? Can that send
I write the following code in simulate.jsp , to receive some String simulationInfos from
I'm trying to write some C# code to get to a specific folder in
I am a programmer, new to jsp, trying to write some code. i have
I want to ask some questions about the JSP and JSON file. I have
Is there a plugin or ability to write some type of JSP or script
I am considering creating some JSP-tags that will always give the same output. For
I write a html file with some JSP in it.A html tag has a
I am printing some values on a JSP from session using < bean:write />
I've installed Tomcat and I've been testing it: I wrote some .html and .jsp

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.