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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T07:48:58+00:00 2026-06-15T07:48:58+00:00

Below is my code. While i am running it shows json syntax exception expected

  • 0

Below is my code. While i am running it shows “json syntax exception expected a string but was begin_object”. I don’t know why it shows the error.

 {
"products": [
    {
        "name": "gam",
        "pplsft": "75665",
        "imei": "Ptwm ",
        "created_at": "2012-12-03 04:58:01"
    },
    {
        "name": "",
        "pplsft": "0",
        "imei": "",
        "created_at": "2012-12-03 05:44:01"
    },
    {
        "name": "gptw",
        "pplsft": "0",
        "imei": "at",
        "created_at": "2012-12-03 05:58:18"
    },
    {
        "name": "",
        "pplsft": "0",
        "imei": "",
        "created_at": "2012-12-03 23:32:06"
    },
    {
        "name": "",
        "pplsft": "0",
        "imei": "",
        "created_at": "2012-12-03 23:35:25"
    }
]
}

and the class file are, but i dont know exactly how to create the class file for json parsing using gson. Can anobdy explain this??

  public class Results  {
public String name;
@SerializedName("pplsft")
public int pplsft;
@SerializedName("imei")
public String imei;
@SerializedName("created_at")
public int created_at;
     }

   public class SearchResponse  {

@SerializedName("products")
public List<Result> products;
@SerializedName("name")
public String name;
@SerializedName("pplsft")
public int pplsft;
@SerializedName("imei")
public String imei;
@SerializedName("created_at")
public int created_at;
public List<Result> getProducts() {
    return products;
}
public void setProducts(List<Result> products) {
    this.products = products;
}
public String getName() {
    return name;
}
public void setName(String name) {
    this.name = name;
}
public int getPplsft() {
    return pplsft;
}
public void setPplsft(int pplsft) {
    this.pplsft = pplsft;
}
public String getImei() {
    return imei;
}
public void setImei(String imei) {
    this.imei = imei;
}
public int getCreated_at() {
    return created_at;
}
public void setCreated_at(int created_at) {
    this.created_at = created_at;
}

   }

This is the main method for calling the data from the json.

    response = gson.fromJson(reader, SearchResponse.class);
Toast.makeText(this,response.name, Toast.LENGTH_SHORT).show();
List<Result> list = response.products;
  • 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-15T07:49:00+00:00Added an answer on June 15, 2026 at 7:49 am

    Your object should be as follows for JSON:

    SearchResponse response = gson.fromJson(reader, SearchResponse.class);
    

    Then to get your list:

    List<Product> mProducts = response.products;
    

    To go through your list you do the following:

    for( Product pro : mProducts ){
        String pName = pro.name;
        ......
    }
    

    or you can just do it manually(get name from the first object;

    mProducts.get(0).name;
    

    Now your class:

    public class SearchResponse  {
    
        @SerializedName("products")
        public List<Product> products;
    
        public class Product {
    
            @SerializedName("name")     
            public String name;
    
            @SerializedName("pplsft")
            public String pplsft;
    
            @SerializedName("imei")
            public String imei;
    
            @SerializedName("created_at")
            public String created_at;
    
        }
    }
    

    your JSON

    {
       "products":[
          {
             "name":"gam",
             "pplsft":"75665",
             "imei":"Ptwm ",
             "created_at":"2012-12-03 04:58:01"
          },
          {
             "name":"",
             "pplsft":"0",
             "imei":"",
             "created_at":"2012-12-03 05:44:01"
          },
          {
             "name":"gptw",
             "pplsft":"0",
             "imei":"at",
             "created_at":"2012-12-03 05:58:18"
          },
          {
             "name":"",
             "pplsft":"0",
             "imei":"",
             "created_at":"2012-12-03 23:32:06"
          },
          {
             "name":"",
             "pplsft":"0",
             "imei":"",
             "created_at":"2012-12-03 23:35:25"
          }
       ]
    }
    

    Perhaps the Solution to this Post could be of some help to you as well.

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

Sidebar

Related Questions

While running the code I've included below I receive the error EntityCommandExecutionException was unhandled
The code below while running on iphone 3g ios 4.2.1 causes an error shown
I get this error, while I'm testing the code below: You have an error
Running the below code with Fiddler shows that plus signs are getting converted to
I have part of the code below: while($array = $result->fetch_assoc() ){ $second_query = INSERT
In the below code, using (SqlDataReader dr = com.ExecuteReader(CommandBehavior.CloseConnection)) { while (dr.Read()) { _emailTemplate.EmailContent
The uncommented code below yields an OperationalError: near? while the commented lines works fine.
In the code below, when I examine the Chars variable while stepping through the
Below code not work, but it's work fine for jsf1.2. Now the framework is
The offending block of code is below. The code almost always works, but sometimes

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.