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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T20:10:36+00:00 2026-06-10T20:10:36+00:00

i m trying to write a method for calling service and get JSON data

  • 0

i m trying to write a method for calling service and get JSON data back in Android application. assume all necessary gloable variables are declared already…

these are the lib i m using:

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

here is my code:

public class JSONParser {

String url = "http://gdata.youtube.com/feeds/api/users/eon/uploads?&v=2&max-   results=50&alt=jsonc"; 

JSONObject jObj = null;
JSONArray ja = null;
String json = "";

// constructor
public JSONParser() {

 }



  public JSONObject getJSONFromUrl(String url){
    try {
          URL urlGetter = new URL(url);
        URLConnection tc = urlGetter.openConnection();
        BufferedReader in = new BufferedReader(new InputStreamReader(
                tc.getInputStream(), "iso-8859-1"), 8);

          StringBuilder sb = new StringBuilder();
        String line = null;
        while ((line = in.readLine()) != null) {
            sb.append(line + "\n");
        }


         json = sb.toString();
    } catch (MalformedURLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

      //parse the string to a JSON object
    try {
        jObj = new JSONObject(json);
    } catch (JSONException e) {
        Log.e("JSON Parser", "Error parsing data " + e.toString());
    }
    return jObj;
   }

it just dose not work, i tried to run in debug mode, when it run to this line:

BufferedReader in = new BufferedReader(new InputStreamReader(
            tc.getInputStream(), "iso-8859-1"), 8);

it complains about : java.net.UnknownHostException: gdata.youtube.com
i don’t know how to solve this problem… any suggestions?
thanks

by the way, in my android manifest, i have permit internet already:

if you look up the url in browser, you can see the json format of ti …and it can be connected…but my code just complaining about unknowhostexception….”http://gdata.youtube.com/feeds/api/users/eon/uploads?&v=2&max- results=50&alt=jsonc”;

  • 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-10T20:10:38+00:00Added an answer on June 10, 2026 at 8:10 pm

    Please put the permissions in your androidManifest.xml

    <uses-permission android:name="android.permission.INTERNET"/>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to write a method that will compute all permutations of a power
I'm trying to write a method that removes all non alphabetic characters from a
I am trying to write a method in Java that accepts a string as
I am trying to write a method that adapts to different types of interfaces
I'm trying to write a method like this: public static T Test<T>() { if
I'm trying to write a method that acts as a setter and takes some
I am trying to write a method, that takes a ComboBox, a DataTable and
I'm trying to write a method to reduce the size of any image 50%
I am trying to write a method that makes a log.txt file if one
I am trying to write a method that reads the contents of a richtext

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.