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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T10:54:25+00:00 2026-05-31T10:54:25+00:00

I have a problem on converting JSON string to object in Android. Here are

  • 0

I have a problem on converting JSON string to object in Android. Here are the JSON structure and Java classes:

JSON:

{
"code":"SUCCEED",
"message":"",
"result":{
    "ccahUserId": 111,
    "ccahUserName":"your_name",
    "userFirstName":"your_first_name",
    "userLastName":"your_last_name",

    //others
}

Java classes:

public class Result<T>{
   public String code;
   public String message;
   public T result;   
}

public class DeviceSetting 
{
    public long ccahUserId;
    public String ccahUserName;
    public String userFirstName;
    public String userLastName;
    //other members

}

Activity:

Gson gson = new Gson();
Result<DeviceSetting> setting = gson.fromJson(result, Result<DeviceSetting>.class);

When I deserialise the JSON string, code and message field were good but result field is null.
I am not familiar with Gson yet, so please help how to fix this problem?

Thanks in advance.

  • 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-31T10:54:26+00:00Added an answer on May 31, 2026 at 10:54 am

    Likely the result field is null because it relies on the type parameter for Result.

    From the GSON documentation for Gson.fromJson(JsonElement, Class<T>) (bolding is mine):

    This method deserializes the Json read from the specified parse tree
    into an object of the specified type. It is not suitable to use if the
    specified class is a generic type
    since it will not have the generic
    type information because of the Type Erasure feature of Java. Therefore, this method should not be used if the desired type is a generic type. Note that this method works fine if the any of the fields of the specified object are generics, just the object itself should not be a generic type. For the cases when the object is of generic type, invoke fromJson(JsonElement, Type).

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

Sidebar

Related Questions

i have a json string im converting to object with a simple eval(string); heres
I have a problem converting a string binary to a decimal I was using
I have a problem while converting a string whose value is dd.mm.yyyy to DateTime
Hi stackoverflow team i have a problem in converting base64 string to bitmap in
I have problem converting from string to date. The first one i Ok: Date
I have a problem with the JSON result of my PHP script. I can't
I have a problem with parsing my JSon Data in an Android application. I
Possible Duplicate: converting C to C# i have problem in converting by c code
I have a problem using data.table: How do I convert column classes? Here is
I am using LaTeX and I have a problem concerning string manipulation. I want

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.