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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T23:18:16+00:00 2026-05-31T23:18:16+00:00

I am having trouble parsing my JSON which i get from javascript. The format

  • 0

I am having trouble parsing my JSON which i get from javascript.
The format of JSON is this:

[{"positions":[{"x":50,"y":50},{"x":82,"y":50},{"x":114,"y":50},{"x":146,"y":50}]},{"positions":[{"x":210,"y":50},{"x":242,"y":50},{"x":274,"y":50}]}]

So far i have been able to get this far:

{"positions":[{"x":50,"y":50},{"x":82,"y":50},{"x":114,"y":50},{"x":146,"y":50}]}

But i also need to now create a class with those positions. I havnt been working on the class, since i tried printing out the output first, but i am unable to break it down further. I am getting this error message:

java.lang.IllegalStateException: This is not a JSON Array.

And my code is this:

    JsonParser parser = new JsonParser();
    String ships = request.getParameter("JSONships");
    JsonArray array = parser.parse(ships).getAsJsonArray();

    System.out.println(array.get(0).toString());
    JsonArray array2 = parser.parse(array.get(0).toString()).getAsJsonArray();
    System.out.println(array2.get(0).toString());

I have also tried to do it this way:

    Gson gson = new Gson() ;
    String lol = (gson.fromJson(array.get(0), String.class));
    System.out.println(lol);

In which case i get:

com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected STRING but was BEGIN_OBJECT

In the end, i want to loop through positions, creating class for each “positions”, which contains a List with another class Position, which has the int x, y.

Thank you for your time.

  • 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-05-31T23:18:18+00:00Added an answer on May 31, 2026 at 11:18 pm

    Define your classes and you will get everything you need using gson:

    public class Class1 {
      private int x;
      private List<Class2> elements;
    }
    

    And the inner class:

    public class Class2 {
      private String str1;
      private Integer int2;
    }
    

    Now you can parse a json string of the outer class just like that:

    gson.fromJson(jsonString, Class1.class);
    

    Your error while using Gson is that you try to parse a complex object in String, which is not possible.

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

Sidebar

Related Questions

I'm having trouble parsing an iso date from my json api/mongodb using rest kit.
i'm still transitioning from as2 to as3, i'm having trouble with parsing XML data
I am having trouble parsing the response from my app. Here is the call
I'm relatively new to jquery/ajax, and I'm having trouble parsing the results from a
I am playing around with parsing JSON in jQuery and I am having trouble.
I'm having trouble parsing this xml file using jquery: <?xml version=1.0 encoding=utf-8?> <?mso-infoPathSolution name=urn:schemas-microsoft-com:office:infopath:BOT-Memos:-myXSD-2011-07-13T14-29-57
I'm having trouble in parsing my JSON data in jQuery autocomplete. My JSON comes
I am having trouble parsing this particular line using sed: /media/file/1.bmp app:Stuff I want:
I'm having trouble parsing a json response. Its created via php and sent back
I am having trouble parsing some returned XML using this command: XML::Parser.string(xml_string).parse Here is

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.