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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:38:55+00:00 2026-05-25T21:38:55+00:00

I have JSONArray and when I decode JSON to HashMap at that time HashMap

  • 0

I have JSONArray and when I decode JSON to HashMap at that time HashMap take last value of JSONArray.

here my code:

QjArray = new JSONArray(Questionresult);
JSONObject json_data  = new JSONObject();
for (int i = 0; i<QjArray.length(); i++) {
    objJMap = new HashMap<String, String>(); 
    json_data = QjArray.getJSONObject(i);

    jQuestionName =json_data.getString("QuestionName");
    objJMap.put("QuestionName",jQuestionName);

    jQuestiontypeid = json_data.getInt("Questiontypeid");
    String Qid = jQuestiontypeid.toString();
    objJMap.put("Questiontypeid", Qid);

    jAnswertypeid = json_data.getInt("Answertypeid");
    String Aid = jAnswertypeid.toString();
    objJMap.put("Answertypeid", Aid);
}

My JSONArray:

This is question list[{"QuestionID":"1","QuestionName":"when you come","Questiontypeid":"1","Answertypeid":"1"},{"QuestionID":"2","QuestionName":"about your words","Questiontypeid":"1","Answertypeid":"2"},{"QuestionID":"3","QuestionName":"you want extra service?","Questiontypeid":"1","Answertypeid":"3"},{"QuestionID":"4","QuestionName":"performance of quality ?","Questiontypeid":"1","Answertypeid":"4"},{"QuestionID":"5","QuestionName":"performance of staff?","Questiontypeid":"1","Answertypeid":"5"},{"QuestionID":"6","QuestionName":"when you left room ?","Questiontypeid":"2","Answertypeid":"1"},{"QuestionID":"7","QuestionName":"your words about roomservice ?","Questiontypeid":"2","Answertypeid":"2"},{"QuestionID":"8","QuestionName":"you like roomservice ?","Questiontypeid":"2","Answertypeid":"3"},{"QuestionID":"9","QuestionName":"performance room service ?","Questiontypeid":"2","Answertypeid":"4"},{"QuestionID":"10","QuestionName":"performance room service staff?","Questiontypeid":"2","Answertypeid":"5"}]
  • 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-25T21:38:56+00:00Added an answer on May 25, 2026 at 9:38 pm

    I think there are certain problems in your logic. For every JSON object u are creating new HashMap object inside for loop, so u will loose any previous data. Also HashMap will override new Data, so you will have only final data. What u can do is that create an arrayList of Hashmap….

         ArrayList<HashMap<String, String>> data = new ArrayList<HashMap<STring, String>>();
        for (int i = 0; i<QjArray.length(); i++) {
    
               objJMap = new HashMap<String, String>(); 
    ........
               data.add(objJMap);
        ...}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have three PHP arrays that I've encoded with json... extra PHP code has
I have a piece of code that needs to handle both JSONObject and JSONArray
Hi I want to create a JSON array. I have tried using: JSONArray jArray
I have this php code $jsonArray = array(); $sql = SELECT ID,CLIENT FROM PLD_SERVERS;
[I have some code to create a JSON array. In this code I am
I have a JSON result that has an array of messages: { messages: [
<%@ page language=java import=net.sf.json.JSONArray %> <% JSONArray arrayObj=new JSONArray(); arrayObj.add(MCA); arrayObj.add(Amit Kumar); arrayObj.add(19-12-1986); arrayObj.add(24);
I'm new to Java and have searched for quite a time now on the
I have an array of JSON objects, some of which contain key/value pairs for
I have a JSON file that I want to parse. For each entry in

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.