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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T01:15:37+00:00 2026-06-02T01:15:37+00:00

I am trying to fetch a JSON file from my website and parse it.

  • 0

I am trying to fetch a JSON file from my website and parse it. So far no luck, unfortunately. I was able to fetch the data using another class called BaslikContainer, however, I need this code to work within another one, which requires Baslik instances in an arraylist, so I needed to remove it and now I can’t make it work.

Can someone please point out the problem in this? No exceptions thrown – I have no idea why this is happening.

package info.funstein.TestHttpGet;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URI;
import java.util.List;

import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

public class TestHttpGet {

    /**
     * @param args
     * @throws Exception 
     */
    public static void main(String[] args) throws Exception{
        BufferedReader in = null;
        HttpClient client = new DefaultHttpClient();
        HttpGet request = new HttpGet();
        request.setURI(new URI("http://dev.funstein.info/baslik.json"));
        HttpResponse response = client.execute(request);
        in = new BufferedReader
                (new InputStreamReader(response.getEntity().getContent()));
        StringBuffer sb = new StringBuffer("");
        String line = "";
        String NL = System.getProperty("line.separator");
        while ((line = in.readLine()) != null) {
            sb.append(line + NL);
        }
        in.close();
        String page = sb.toString();


        GsonBuilder gsonBuilder = new GsonBuilder();
        Gson gson = gsonBuilder.create();
        Basliklar basliklar = gson.fromJson(page, Basliklar.class);
        System.out.println(basliklar); 

        }
    }
class Basliklar {
    private List<Baslik> basliklar;

    @Override
    public String toString() {
        return String.format("[Basliklar: %1$s]", basliklar);
    }
}

class Baslik {
    private String baslikAdi;
    private String baslikAcan;
    private int baslikID;

    public String getBaslikAdi() {
        return baslikAdi;
    }

    public void setBaslikAdi(String baslikAdi) {
        this.baslikAdi = baslikAdi;
    }

    public String getBaslikAcan() {
        return baslikAcan;
    }

    public void setBaslikAcan(String baslikAcan) {
        this.baslikAcan = baslikAcan;
    }

    public int getBaslikID() {
        return baslikID;
    }

    public void setBaslikID(int baslikID) {
        this.baslikID = baslikID;
    }

    @Override
    public String toString() {
        return String.format("[Baslik: baslikAdi=%1$s, baslikAcan=%2$s, baslikID=%3$d]",
                baslikAdi, baslikAcan, baslikID);
    }
}
  • 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-02T01:15:38+00:00Added an answer on June 2, 2026 at 1:15 am

    Your Input JSon String is wrong.

    Using Gson.toJson(Object) the follwing way

    GsonBuilder gsonBuilder = new GsonBuilder();
    Gson gson = gsonBuilder.create();
    Basliklar b = new Basliklar();
    b.basliklar = new ArrayList<Baslik>();
    Baslik b1 = new Baslik();
    b1.setBaslikAdi("Deneme1");
    b1.setBaslikAcan("funstein");
    b1.setBaslikID(0);
    b.basliklar.add(b1);
    Baslik b2 = new Baslik();
    b2.setBaslikAdi("Deneme2");
    b2.setBaslikAcan("qeremqazan");
    b2.setBaslikID(1);
    b.basliklar.add(b2);
    
    LoggerFactory.getLogger(TestHttpGet.class).debug(gson.toJson(b));
    

    produces the following Json String:

    {"basliklar":[{"baslikAdi":"Deneme1","baslikAcan":"funstein","baslikID":0},{"baslikAdi":"Deneme2","baslikAcan":"qeremqazan","baslikID":1}]}
    

    Your JSON input String is:

    {"basliklar":[{"baslik":{"baslikAdi":"Deneme1","baslikAcan":"funstein","baslikID":"0"}},{"baslik":{"baslikAdi":"Deneme2","baslikAcan":"qeremqazan","baslikID":"1"}}]}
    

    There is are additional / unexpected “baslik:” elements in your input String.

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

Sidebar

Related Questions

I'm trying to fetch data from a div (based on his id), using PHP's
I'm trying to fetch information from a JSON web service with this code, using
I'm trying to parse an NSString that contains JSON data into an NSDictionary using
I am trying to fetch data from database using php and send it to
I am trying to fetch information from a JSON file but nothing comes in
I am trying to populate a collection with data from a JSON file. I'm
I'm trying to fetch and parse an XML-file through JavaScript. I don't control the
I am trying to fetch the below json content using a magazine api. The
I am trying to fetch a json string from a password protected url. I
I'm trying to fetch some data from Yahoo's API and Im running into some

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.