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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T19:31:29+00:00 2026-06-13T19:31:29+00:00

I’m new to JSON and I’m really struggling to parse this layout with GSON

  • 0

I’m new to JSON and I’m really struggling to parse this layout with GSON in Java

{"time_entries":
[
    {"hours":1.0,
    "id":311,
    "created_on":"2012-11-02T14:53:38Z",
    "user":{"id":7,"name":"blah"},
    "issue":{"id":266},
    "activity":{"id":10,"name":"blah"},
    "updated_on":"2012-11-02T14:53:38Z",
    "comments":"blah",
    "spent_on":"2012-11-02",
    "project":{"id":10,"name":"blah"}},

    {"hours":6.0,
    "id":310,
    "created_on":"2012-11-02T13:49:24Z",
    "user":{"id":4,"name":"blah"},
    "issue":{"id":258},
    "activity":{"id":9,"name":"blah"},
    "updated_on":"2012-11-02T13:49:24Z",
    "comments":"blah",
    "spent_on":"2012-11-02",
    "project":{"id":11,"name":"blah"
    }}
],
"offset":0,
"limit":2,
    "total_count":306
}

If it helps it’s the output the Redmine API gives you for time entries.
I’m struggling to understand some of the basic JSON concepts like objects and arrays and I haven’t been able to find an example with a layout similar to this.

My main concern in using the tutorials I have read is that the multiple ID fields will get confused.

What’s the best way to parse this without tying myself in knots?

I’m not set on using Gson and would be happy for a solution using Jackson or the built in library. The end goal is for Android implementation so I would prefer to use use serialization.

Thanks

EDIT:

My attempt at an “object model”

public class TimeResponse {
     public List<Time_Entry> time_entries;

        @SerializedName("hours")
        public String hours;

        @SerializedName("id")
        public int id;

        @SerializedName("created_on")
        public String created_on;

        @SerializedName("name")
        public String name;

        @SerializedName("updated_on")
        public int updated_on;

        public int page;

        @SerializedName("comments")
        public double comments;

        @SerializedName("spent_on")
        public String spent_on;

        @SerializedName("offset")
        public String offset;

        @SerializedName("limit")
        public String limit;

        @SerializedName("total_count")
        public String total_count;

}

I’m am unsure as to what I should write for my results list (if I need one) and I’ve have only declared an id and name string once despite it being used multiple times?

I am aware I shouldn’t be using strings for my hours I’m in the process of looking into what the hours field actually contains. I believe the tutorial is slightly out of date in that the last three fields are not represented in the same way now in the Twitter API.

  • 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-13T19:31:31+00:00Added an answer on June 13, 2026 at 7:31 pm

    I am not sure what you mean by ‘multiple ID fields’. There is no such thing as an ID in JSON.

    Regarding the basic JSON concepts, see http://json.org/:

    Object:

    An object is an unordered set of name/value pairs. An object begins with { (left brace) and ends with } (right brace). Each name is followed by : (colon) and the name/value pairs are separated by , (comma).

    Array:

    An array is an ordered collection of values. An array begins with [ (left bracket) and ends with ] (right bracket). Values are separated by , (comma).

    Value:

    A value can be a string in double quotes, or a number, or true or false or null, or an object or an array. These structures can be nested.

    String:

    A string is a sequence of zero or more Unicode characters, wrapped in double quotes, using backslash escapes. A character is represented as a single character string. A string is very much like a C or Java string.

    Number:

    A number is very much like a C or Java number, except that the octal and hexadecimal formats are not used.

    Edit:

    There is not much you can do to simlify the JSON from your question except pretty-print it:

    {
        "time_entries": [
            {
                "hours": 1,
                "id": 311,
                "created_on": "2012-11-02T14:53:38Z",
                "user": {
                    "id": 7,
                    "name": "blah"
                },
                "issue": {
                    "id": 266
                },
                "activity": {
                    "id": 10,
                    "name": "blah"
                },
                "updated_on": "2012-11-02T14:53:38Z",
                "comments": "blah",
                "spent_on": "2012-11-02",
                "project": {
                    "id": 10,
                    "name": "blah"
                }
            },
            {
                "hours": 6,
                "id": 310,
                "created_on": "2012-11-02T13:49:24Z",
                "user": {
                    "id": 4,
                    "name": "blah"
                },
                "issue": {
                    "id": 258
                },
                "activity": {
                    "id": 9,
                    "name": "blah"
                },
                "updated_on": "2012-11-02T13:49:24Z",
                "comments": "blah",
                "spent_on": "2012-11-02",
                "project": {
                    "id": 11,
                    "name": "blah"
                }
            }
        ],
        "offset": 0,
        "limit": 2,
        "total_count": 306
    }
    

    Perhaps you can see that you have one JSON Object with four name/value pairs:

    • time_entries
    • offset
    • limit
    • total_count

    The last three of these have simple numeric values while the first (time_entries) is an Array of two more Objects. Each one of these two Objects conssits of various name/value pairs. The name/value pair id is just one of these.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I want use html5's new tag to play a wav file (currently only supported
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into

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.