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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T01:47:50+00:00 2026-05-22T01:47:50+00:00

I have a JSON response that looks like this. I want to extract the

  • 0

I have a JSON response that looks like this. I want to extract the values of “text” and put them into a Set of Strings (i.e. I don’t necessarily need the entire JSON to be derialised).

I am using the GSON library

So far my method looks like this (It’s obviously wrong):

 public static Response deserialise(String json){
  Gson gson = new Gson();
  Response r = gson.fromJson(json, Response.class);
  return r;
 }

I am calling deserialise with this:

Response r = deserialise(json);
System.out.println("[status]: "+r.getStatus());  // works fine
        Collection<Keyword> coll = r.getKeywords();
        Iterator<Keyword> itr = coll.iterator();
        while(itr.hasNext()){
System.out.println(itr.next().getWord());        //prints null every time
 }

Response is a class with the following member variables (with getters and setters):

private String status;
private String usage;
private String language;
private Collection<Keyword> keywords; 

Keyword is a class with the following member variables (with getters and setters):

private String word;
private String relevance;

The JSON looks like this:

{
"status": "OK",
"usage": "By accessing AlchemyAPI or using information generated by AlchemyAPI, you are agreeing to be bound by the AlchemyAPI Terms of Use: http://www.alchemyapi.com/company/terms.html",
"url": "http://www.theage.com.au/world/aussie-trying-to-make-a-difference-gunned-down-20110510-1egnv.html",
"language": "english",
"keywords": [
    {
        "text": "Mr McNichols",
        "relevance": "0.99441"
    },
    {
        "text": "Ms Benton",
        "relevance": "0.392337"
    },
    {
        "text": "Detroit",
        "relevance": "0.363931"
    },
    {
        "text": "Crocodile Hunter",
        "relevance": "0.350197"
    }
    ]
}

The problem is that the Collection of Keywords returns null values – although it seems to have the correct size, which is positive.

  • 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-22T01:47:51+00:00Added an answer on May 22, 2026 at 1:47 am

    This just works:

    public class Keyword {
        public String text;
        public String relevance;
    }
    
    
    public class MyJSON {
        public String status;
        public String usage;
        public String language;
        public Collection<Keyword> keywords;
    }
    

    In the main method

            String str = "{\"status\": \"OK\","+
            "\"usage\": \"By accessing AlchemyAPI or using information generated by AlchemyAPI, you are agreeing to be bound by the AlchemyAPI Terms of Use: http://www.alchemyapi.com/company/terms.html\","+
            "\"url\": \"http://www.theage.com.au/world/aussie-trying-to-make-a-difference-gunned-down-20110510-1egnv.html\","+
            "\"language\": \"english\","+
            "\"keywords\": ["+
                "{"+
                    "\"text\": \"Mr McNichols\","+
                    "\"relevance\": \"0.99441\""+
                "},"+
                "{"+
                    "\"text\": \"Ms Benton\","+
                    "\"relevance\": \"0.392337\""+
                "},"+
                "{"+
                    "\"text\": \"Detroit\","+
                    "\"relevance\": \"0.363931\""+
                "},"+
                "{"+
                    "\"text\": \"Crocodile Hunter\","+
                    "\"relevance\": \"0.350197\""+
                "}"+
                "]"+
            "}";
    
            Gson gson = new Gson();
            MyJSON mj = gson.fromJson(str, MyJSON.class);
            System.out.println(mj.language);
            for(Keyword k: mj.keywords)
                System.out.println(k.text+":"+k.relevance);
    

    This prints

    english
    Mr McNichols:0.99441
    Ms Benton:0.392337
    Detroit:0.363931
    Crocodile Hunter:0.350197
    

    Look carefully at my Keyword class!(and my JSON string starts with {).

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

Sidebar

Related Questions

I have a JSON response that looks like this [ { alias: Server1, hostgroup_worst_service_state:
I have a json that looks like this {abcd: { id: 1234, response: authenticated,
I have a JSON response from a web server that looks like this: {success:true,
Hi i have a json file that looks like this: { links_1: [ {
I have a simple class in asp.net mvc that looks like this: public class
Suppose I have a PHP script that returns a json response. It looks something
I have a Nancy JSON REST service that uses the following serialisation code... FormatterExtensions.AsJson(this.Response,
I have some jQuery that looks like this: $.ajax({ type: POST, url: /Customer/CancelSubscription/<%= Model.Customer.Id
I have a hash being posted to my Rails app that looks like this:
I'm using ExtJs 4. I have a panel that looks something like this: var

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.