Note that there are some explanatory texts on larger screens.

plurals
  1. PONot able to load JSON Data in Android
    primarykey
    data
    text
    <p>I am new in JSON Parsing and need some help in retrieving data from a JSON URL... I have read many tutorials on JSON Parsing and they all helped me a lot but not I am stuck.. I am trying to retrieve data from a</p> <pre><code>URL = "http://mygogolfteetime.com/iphone/topfive/155" </code></pre> <p>but my <code>Json object</code> returns <strong>null</strong> value in the log.</p> <p>However I can retrieve the same data from another</p> <pre><code>URL = "http://api.mygogolfteetime.com/top_5.php?id=155&amp;apikey=eart3562@#bety7*&amp;6b12zAf*&amp;etrqvbn*&amp;LMQW" </code></pre> <p>I am also attaching my code so that one can help me in solving my problem..</p> <p>Code for My Test Activity:</p> <pre><code>public class TestActivity extends Activity { private static final String url = "http://mygogolfteetime.com/iphone/topfive/155"; private static final String TAG = "Top5"; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Log.v(TAG, "URL: "+String.valueOf(url)); JsonParser jParse = new JsonParser(); JSONObject json = jParse.getJSONfromUrl(url); Log.v(TAG, "Json: "+String.valueOf(json)); } } </code></pre> <p>This is the code of my JsonParser Activity:</p> <pre><code>public class JsonParser { static InputStream is; static JSONObject jObj; static String json = null; private static final String TAG = "Top5"; public JSONObject getJSONfromUrl(String url) { try { DefaultHttpClient httpClient = new DefaultHttpClient(); HttpPost httpPost = new HttpPost(url); HttpResponse httpResponse = httpClient.execute(httpPost); HttpEntity httpEntity = httpResponse.getEntity(); is = httpEntity.getContent(); } catch(UnsupportedEncodingException e) { e.printStackTrace(); } catch(ClientProtocolException e) { e.printStackTrace(); } catch(IOException e) { e.printStackTrace(); } try { BufferedReader reader = new BufferedReader(new InputStreamReader(is, "iso-8859-1"), 8); StringBuilder sb = new StringBuilder(); String line = null; while((line = reader.readLine()) != null) { sb.append(line + "\n"); } is.close(); json = sb.toString(); } catch(Exception e) { e.printStackTrace(); } try { jObj = new JSONObject(json); } catch(JSONException e) { e.printStackTrace(); } return jObj; } } </code></pre> <p>I have also added the permission for the Internet in the Manifest file...</p> <pre><code>&lt;uses-permission android:name="android.permission.INTERNET"/&gt; </code></pre> <p>Thanks in advance...</p> <p>sorry for my bad English.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload