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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T22:46:32+00:00 2026-06-16T22:46:32+00:00

I have some trouble with parsing a JSON response. The response data: { deal:

  • 0

I have some trouble with parsing a JSON response. The response data:

{
    "deal": {
        "categorie": {
            "description": "Offres Shopping",
            "idcategorie": "1",
            "nom": "Shopping"
        },
        "conditions": "2 personne au plus",
        "dateAjout": "2013-01-07T00:00:00+01:00",
        "dateExp": "2013-01-31T00:00:00+01:00",
        "description": "nuit dans un hotel 5 etoile",
        "heurexp": "12",
        "iddeal": "1",
        "minutesexp": "30",
        "prestataire": {
            "adresse": "Qu zohour 44",
            "codePostale": "12600",
            "description": "Hotel 5 etoiles",
            "idprestataire": "1",
            "nom": "Hotel ronald",
            "pays": "France",
            "telephone": "99999999",
            "ville": "Brest"
        },
        "prix": "80.0",
        "prixHabituel": "200.0",
        "tags": "hotel",
        "titre": "Nuit 5 etoiles"
    }
}

When trying to parse this response to a List<Deal> I get this exception:

com.google.gson.JsonObject cannot be cast to com.google.gson.JsonArray

This is the code that I am using for the parse:

if (reponse != null && !reponse.isEmpty()) {
System.out.println(reponse);

Gson g = new Gson();
JsonParser parser = new JsonParser();
JsonObject jObject = parser.parse(reponse).getAsJsonObject();
JsonArray jArray =  jObject.getAsJsonArray("deal");  // here goes the Exception
for (JsonElement elem : dealArray) {
deals.add(g.fromJson(elem, Deal.class));
}

    System.out.println(deals.toString());
    return "success";
}

thanks

  • 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-16T22:46:33+00:00Added an answer on June 16, 2026 at 10:46 pm

    Well, deal is not a JSON array, its a JSON object. Hence the exception. A JSON array, for reference, would look more like this:

    "deal" : [{"attr" : "value"}, {"attr" : "value"}]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some trouble understanding parsing XML structures with SAX. Let's say there is
I'm having a bit of trouble parsing some returned JSON. I'm fairly new to
Iam having some serious trouble parsing data from Giantbomb. I've tried almost every trick
I am Rails newbie and having some trouble passing parameters to form. I have
Having some trouble with R's garbage collection, when passing objects to C++. We have
I have some trouble when I try to map object to int . My
I have some trouble with my trac installation (version 11.4). What should I do
I have some trouble with jquery ui-events: In my application, there are some sliders.
I have some trouble achieving adequate real-time performance from my application and wondering if
i seem to have some trouble installing autopy.h https://github.com/msanders/autopy/#introduction i already tried the installation

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.