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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T08:19:56+00:00 2026-06-10T08:19:56+00:00

I am using GSON to decode JSON strings that are returned from our server.

  • 0

I am using GSON to decode JSON strings that are returned from our server. I haven’t had any problems, until I ran into this one particular JSON return from the API. The return is in the following format:

“success”:1,”errors”:[],”data”:{“524”:{“id”:”524″}, “525”:{“id”:”525″}}

For the other returns I had data as an array of a class of my own creation, but for this return it says that it is an object and not an array. So how should I format my class?

***edit: What I am having trouble with is that the ‘524’ and ‘525’ fields are not static names. They are dependent on what the user’s credentials are. There could be fields 323, 324, 325 or a single one 123. It all depends. How would I be able to handle this dynamically?

SOLVED*
What I had to was make ‘data’ a <String, Object> hashmap in my custom class. Then after the first decoding, I turned ‘data’ into an array of type Object []. Then for each Object[i], I converted it into a JSON string. After that I used gson.fromJson() to convert it into what I had originally intended for it to be.

  • 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-10T08:19:57+00:00Added an answer on June 10, 2026 at 8:19 am

    If the API is giving inconsistent results and you can’t find a reason on your end why it is doing so, one option is to parse the object into a GSON JSONObject o = gson.fromJson(String) and then convert the data to a list if it is not one already by doing o.getElement("data").isList(), etc..

    When this is complete, you can then create the object via gson.fromJson(JSONObject,Class). The alternative is to have two classes, one for each instance, but this seems sloppy if this is the only reason to have two different classes.

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

Sidebar

Related Questions

I've recently started using GSON library for deserializing JSON that comes from web service
I'm trying to parse some JSON object strings that I'm getting using gson-1.6.jar I
I have a method for reading JSON from a service, I'm using Gson to
I'm using Gson to convert Json to an object in Java. Json that i'm
I am tring to map json data using Gson from a URL to my
I am sending a json object from java to php. I am using gson
I have some JSON that I am deserializing using Gson. { resp: { posts:
So I'm using GSON to parse JSON from an API and am stuck as
I'm using GSON on my Java EE server to provide some json to views.
I am using Gson to parse Json. What I don't understand what the return

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.