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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T23:35:32+00:00 2026-06-04T23:35:32+00:00

I have this JSON {A:valA, B:[valB], C:valC, D:valD, data:[{ data1:dval1, data2:dval2, data3:dval3, data4:dval4,}], F:valF}

  • 0

I have this JSON

{"A":"valA",
"B":["valB"],
"C":"valC",
"D":"valD",
"data":[{
    "data1":"dval1",
    "data2":"dval2",
    "data3":"dval3",
        "data4":"dval4",}],
"F":"valF"}

Java Object:

public class ABCDObject {
        private String A;
        private String B;
        private String C;
        private String D;
        private List<String> data = new ArrayList<String>(){
                {
                        add("data1");
                        add("data2");
                        add("data3");
                        add("data4");
                        }
                };
        private String F;

        //getters for the above A,B,C,D, and F 
                public List<String> getData() {
                return data;
        }

Main class

Gson gson = new Gson();
        ABCDObject abcdObj = gson.fromJson(response, ABCDObject.class);

I am trying to access value of C as

abcdObj.getC();

I am getting the error
com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected a string but was BEGIN_ARRAY at line 9 column 17

Another question is how to access the value of data–> data1 and so on

  • 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-04T23:35:34+00:00Added an answer on June 4, 2026 at 11:35 pm

    The JSON doesn’t match the object, including:

    • B is an array in the JSON, and a String in ABCDObject
    • data is an array of objects with four properties in the JSON, and an array of strings in ABCDObject.

    Edit with example

    Using the following two classes, and fixing the mal-formed JSON (the spurious comma after data4), this works as expected.

    Data – holds each element of the “data” array, each data object has four data fields.

    public class Data {
        private String data1;
        private String data2;
        private String data3;
        private String data4;
        // Plus getters, setters, toString
    }
    

    JsonHolder – encapsulates the entire JSON object.

    import java.util.List;
    
    public class JsonHolder {
        private String A;
        private List<String> B;
        private String C;
        private String D;
        private List<Data> data;
        private String F;
        // Plus getters, setters, toString
    }
    

    sanity check

    public static void main(String[] args) {
        Gson gson = new Gson();
        JsonHolder json = gson.fromJson(JSON_STRING, JsonHolder.class);
        System.out.println(json);
    }
    

    output

    JsonHolder{A='valA', B=[valB], C='valC', D='valD', data=[Data{data1='dval1', data2='dval2', data3='dval3', data4='dval4'}], F='valF'}
    

    Note that attempting to work around the malformed JSON by using JsonReader.setLenient(true) won’t work in this case; it only handles extra commas at the end of an array (collection), not in an object itself as your example JSON contains.

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

Sidebar

Related Questions

I have this json content inside a var in php: { data: [ {
I have this json info: data.ContactName data.ContactEmal data.Departement I Would like to have a
I have this JSON data: var people = [ { name : John, age
I have this JSON format: string jsonFormat = @{ Applications: { data: { Application
I have this json data: [ {ID:1,name:google,IP:69.5.33.22,active:true}, {ID:2,name:bing,IP:70.5.232.33,active:false} ] I want to get the
i have this json data and i want to get length of this json
I have this json code: { data: [ { name: John, id: 11 },
I have this json array [ { Company: { id: 19, features_id: null, features:
I have this JSON from Google GeoCode and I need to decode this and
I have this JSON: var myVar = { 9:Automotive & Industrial, 1:Books, 7:Clothing };

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.