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

The Archive Base Latest Questions

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

I have a large JSON file that contains A LOT of similar code. It’s

  • 0

I have a large JSON file that contains A LOT of similar code. It’s similar to this:

...,"techs":{"t1":{"level":24,"able":true},"t2":{"level":23,"able":true},"t3":{"level":20,"able":true},"t4"...,"t5"...

It has since t1 until t510… For this reason, I have to create an activity for each tN, so I have to create 510 activities! 0.0

To get acces to each tN I use the following lines:

       Gson gson = new Gson();
        Planets json = gson.fromJson(str, Planets.class);

        System.out.println(json.techs.t1.level);
        System.out.println(json.techs.t2.level);
                         etc...

So I wanna know if there’s the possibility to change t1 for a variable, so that I only have to change the variable to access t2 in a single activity.

For example: String tech = t456; System.out.println(json.techs.tech.level);

Thank you very much in advance!

  • 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-01T01:36:53+00:00Added an answer on June 1, 2026 at 1:36 am

    It’s all just about your imagination 😉

    I will come out from this JSON snippet

    "techs":{"t1":{"level":24,"able":true},"t2":{"level":23,"able":true},"t3":{"level":20,"able":true}}
    

    This is easily representable as this structure

    HashMap<String, InnerObject>
    

    where InnerObject class is defined like this:

    class InnerObject {
        int level;
        boolean able;
    }
    

    So everything you need is class, where single field will be called techs and it will be defined like this:

    class JSONWrapper {
        // another variables
        HashMap<String, InnerObject> techs;
    }
    

    To access fields after, you can use:

    String techId = "t546";
    InnerObject = JSONWrapperInstance.techs.get(techId);
    

    Whole code:

    String str = "... contains JSON string ...";
    JSONWrapper JSONWrapperInstance = new Gson().fromJson(str, JSONWrapper.class);
    

    And you can walk through all items in HashMap like this:

    Iterator<String> iterator = JSONWrapperInstance.techs.keySet().iterator();
    while(iterator.hasNext()){
        InnerObject = JSONWrapperInstance.techs.get(iterator.next());
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a large XML file (converted to JSON) that consists of multiple repeating
Similar to this post need to send a large 30MB JSON file to the
I have a file that is structured in a large multidimensional structure, similar to
I have a very large .json file on disk. I want to instantiate this
Hey. I have this javascript file that I'm getting off the web and it
I have a huge chunk, so large that I can't manually edit the file
So, I have a file with a large JSON array of objects, and unfortunately,
I am using the code in this question NSURLConnection download large file (>40MB) to
I have a php script that outputs a json-encoded object with large numbers (greater
I have a large JSON file with more than 200 items. There are 5

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.