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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T08:55:46+00:00 2026-06-14T08:55:46+00:00

Looking at this Json file, KEY is always a String, but VALUE sometimes is

  • 0

Looking at this Json file, KEY is always a String, but VALUE sometimes is a String but sometimes is an typed object with two String fields.

How can I parse it using GSON?

{
    "property": [
        {
            "key": "key_A",
            "value": "value_A"
        },
        {
            "key": "key_B",
            "value": "value_B"
        },
        {
            "key": "key_C",
            "value": {
                "param_C_1": "value_C_1", 
                "param_C_2": "value_C_2"

            }
        }
    ]
}
  • 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-14T08:55:47+00:00Added an answer on June 14, 2026 at 8:55 am

    The first thing is parsing this json file to java that can be done
    this way :-

     try {
                    InputStream is;
                    //read the whole json file stored in assets
    //below is android way of opening file from local resource folder, you can use other means to open
                    is = getApplicationContext().getAssets().open("jsonfile.json");
                    int size = is.available();
    
                    byte[] buffer = new byte[size];
    
                    is.read(buffer);
    
                    is.close();
    
                    //convert the json file to string
                    String bufferString = new String(buffer);
    
                    JSONObject jsonObject;
                    JSONArray jsonArray;
                    jsonObject = new JSONObject(bufferString);
                    jsonArray=jsonObject.getJSONArray("property");
                    for (int i=0;i<jsonArray.length();i++){
                        jsonObject = jsonArray.getJSONObject(i);
                        JSONObject s = jsonArray.optJSONObject(i);
                        String s2 = s.getString("value");
                        if(s2.contains("{")){
                            JSONObject jobject = new JSONObject(s2);
                            String valueUnderValue1 = jobject.getString("param_C_1");
                            String valueUnderValue2 = jobject.getString("param_C_2");
                        }
                    }
    
    
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                            } catch (JSONException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
    
    
                }
    

    Then make a class which will have all the values you got from the json file.
    Say that class is MyClass, containing all of the values you got from json file.

    make MyClass object and then

    MyClass obj = new MyClass();
    Gson gson = new Gson();
    JSONObject onj = new JSONObject();
            JSONArray userDataValues = new JSONArray();
    //again convert to json
    userDataValues.put(new JSONObject(gson.toJson(obj)));
    //serialized the object
    onj.put("property", userDataValues);
    

    I hope this is what you want.

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

Sidebar

Related Questions

I have parsed a given CSS file/string into a JSON object like so: {
I tried looking this up on here but couldnt find a proper answer. I
Looking at this jQuery example, how can I modify the code so that it
I was looking at this code of a sieve of eratosthenes but i still
I am looking to populate a combo box with a Json file that is
So I have this JSON object: [ { branch_id: 1, issue_id: 1, user_id: 5,
The project requirements are odd for this one, but I'm looking to get some
I am trying to load and parse a JSON file in Python . But
Is there any tool available that can convert a json file to a xml
Looking at this article: http://www.galloway.me.uk/tutorials/singleton-classes/ I have implemented a singleton, my question is the

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.