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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T12:12:56+00:00 2026-06-02T12:12:56+00:00

I have been using GSON library to parse all the json string and get

  • 0

I have been using GSON library to parse all the json string and get a JSON object.
But now I need to parse is like this:

{
   "status":1,
   "info":[
      {
         "\u5a31\u4e50":"\u51b7\u76d8,\u9ad8\u811a\u676f,\u6211\u7684\u7cd6\u679c\u5c4b,\u670d\u52a1\u4e1a\u6d88\u8d39\u52b5"
      },
      {
         "\u7f8e\u5986":"\u4e2a\u62a4|\u5316\u5986#\u9762\u90e8\u62a4\u7406,\u4e2a\u4eba\u536b\u751f,\u8eab\u4f53\u62a4\u7406,\u9999\u6c34\u9999\u6c1b,\u6c90\u6d74|\u7f8e\u53d1\u7528\u54c1,\u5f69\u5986,\u7cbe\u6cb9SPA,\u773c\u90e8\u62a4\u7406,\u78e8\u7802\u53bb"
      },
      {
         "\u8863\u670d":"\u670d|\u9970|\u978b|\u5e3d#\u670d\u88c5,\u978b\u9774,\u5185\u8863,\u914d\u9970,\u536b\u8863,\u4f11\u95f2\u88e4,T\u6064,\u88d9\u5b50,\u886c\u886b,\u9488\u7ec7\u886b,\u5a74\u5e7c\u513f\u670d\u9970"
      }
   ],
   "total":3
}

The key fields are dynamic, so I don’t know how to write a model class to read this.

  • 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-02T12:13:01+00:00Added an answer on June 2, 2026 at 12:13 pm

    How would you like your model class to look?

    status and total would probably be int, so that only leaves info.

    As an experiment, just add a field Object info and see how Gson would set it to an ArrayList<LinkedHashMap<String, String>> — ugly and hard to access by key, but all the data is there. Given that information, the fastest way to model a class would be:

    class Something {
      int status;
      List<Map<String, String> info;
      int total;
    }
    

    If you have control over how that JSON is generated, I suggest changing the structure of info from an array of objects [{a:b},{c:d},{e:f}] to just an object {a:b,c:d,e:f}. With this, you could just map it to a Map<String, String> with all the benefits like access by key, keys() and values():

    class Something {
      int status;
      Map<String, String> info;
      int total;
    }
    

    If you want the latter model class without changing the JSON format, you’ll have to write a TypeAdapter (or JsonDeserializer if you’re only interested in parsing JSON, not generating it from your model class).

    Here’s a JsonDeserializer hat would map your original info JSON property to a plain Map<String, String>.

    class ArrayOfObjectsToMapDeserializer
        implements JsonDeserializer<Map<String, String>> {
    
      public Map<String, String> deserialize(JsonElement json, Type typeOfT,
          JsonDeserializationContext context) throws JsonParseException {
        Map<String, String> result = new HashMap<String, String>();
    
        JsonArray array = json.getAsJsonArray();
        for (JsonElement element : array) {
          JsonObject object = element.getAsJsonObject();
          // This does not check if the objects only have one property, so JSON
          // like [{a:b,c:d}{e:f}] will become a Map like {a:b,c:d,e:f} as well.
          for (Entry<String, JsonElement> entry : object.entrySet()) {
            String key = entry.getKey();
            String value = entry.getValue().getAsString();
            result.put(key, value);
          }
        }
        return result;
      }
    }
    

    You need to register this custom JsonDeserializer similar to this:

    GsonBuilder builder = new GsonBuilder();
    builder.registerTypeAdapter(
        new TypeToken<Map<String, String>>() {}.getType(),
        new ArrayOfObjectsToMapDeserializer());
    Gson gson = builder.create();
    

    Note that this registers the custom deserializer for any Map<String, String> regardless in what class it is encountered. If you don’t want this, you’ll need to create a custom TypeAdapterFactory as well and check the declaring class before returning and instance of the deserializer.

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

Sidebar

Related Questions

I have been using json.NET successfully in projects for some time now without any
I have been using these files all day... And then suddenly this is now
I have been using the Scanner object to take in input until now and
I have been using the following regex to replace all punctuation in a string:
I have been using form inheritance for a while now but without doing much
I have been using the python logging module for quite some time now, but
I have been using ajax loaded data for a while now, but I am
I have been using Haskell's STM library and I really like the ability to
I have been using Castle MonoRail for the last two years, but in a
I have been using C# for a while now, and going back to C++

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.