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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:57:14+00:00 2026-05-26T18:57:14+00:00

I have a JSON string such as below. That comes from a Website (the

  • 0

I have a JSON string such as below. That comes from a Website (the URL outputs below to a page) which I’m using in an android application.

{"posts": [{"id":"0000001","longitude":"50.722","latitude":"-1.87817","position":"Someplace 1","altitude":"36","description":"Some place 1 "},{"id":"0000002","longitude":"50.722","latitude":"-1.87817","position":"Some PLace 2","altitude":"36","description":"Some place 2 description"}]}

I would like to deserialize this into a List where I can iterate through them later on the application. How do I do this? I have created a class with properties and methods and a List class as below and then using fromJson to deserialize it, but it returns NULL. Hope the question is clear and many thanks in advance.

ListClass

package dataaccess;

import java.util.List;

public class LocationList {
    public static List<Location> listLocations;

    public void setLocationList(List <Location> listLocations) {
        LocationList.listLocations = listLocations;
    }

    public List<Location> getLocationList() {
        return listLocations;
    }
}

GSON

public LocationList[] getJsonFromGson(String jsonURL) throws IOException{
    URL url = new URL(jsonURL);
    String content = IOUtils.toString(new InputStreamReader(url.openStream()));
    LocationList[] locations =  new Gson().fromJson(content, LocationList[].class);

    return locations;
}
  • 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-26T18:57:15+00:00Added an answer on May 26, 2026 at 6:57 pm

    You try to deserialize into an array of LocationList objects – that surely wasn’t your intent, was it? The json snippet doesn’t contain a list of lists.

    I would drop the class LocationList (except it ought to be extened in future?), and use a pure List. Then, you have to create a type token like this:

    java.lang.reflect.Type type = new com.google.gson.reflect.TypeToken<ArrayList<Location>>() {}.getType();
    List<Location> locations = new Gson().fromJson(content, type);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a C# method which generates a JSON string that Google charts requires.
I have a web service which returns a list of JSON Objects...such as below:
I have a valid JSON String that I want to tidy/format such that each
I have a json string saved in my db. When i retrieve it from
I have one JSON that is coming in a string format. I need to
I have a spring action that I am rendering some json from the controller,
I have a returned JSON string which I have parsed and put through into
I have a JAX-RS resource, which gets its paramaters as a JSON string like
I have the following JSON string coming from external input source: {value: "82363549923gnyh49c9djl239pjm01223", id:
I am reading string data from a PLIST which I am using to create

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.