in Android while parsing JSON, it parse only 10 items of JSON array. while debuging i found out that query string after connection.openConnection() ; returning null query String for example http://www.example.com/recent_summary/?count=20 it doesnot matter if i decrease the count to 5 it still return 10 items. but, when i browse the URL in browner. it return all 20 items .. i thing its something wrong with my code.. server side working fine and one more thing that when i was checking openConnection() declaration(URL.java) in android Studio i found lot of red lines .. noob here dnt know whether it will help or not but Please help me out.
public class MainListActivity extends ActionBarActivity { protected String TAG = MainListActivity.class.getSimpleName(); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main_list); if(isNetworkAvailable()) { GetPostsTask getPostsTask = new GetPostsTask(); getPostsTask.execute(); }else { Toast.makeText(this,"No Network", Toast.LENGTH_SHORT).show(); } } private boolean isNetworkAvailable(){ ConnectivityManager manager =(ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = manager.getActiveNetworkInfo(); boolean isAvailable = false ; if (networkInfo != null && networkInfo.isConnected()){ isAvailable = true ; } return isAvailable; } private class GetPostsTask extends AsyncTask<Object, Void, String>{ protected String doInBackground(Object...arg){ JSONObject jsonResponse ; try{ URL url = new URL(http://www.example.com/recent_summary/?count=20 ); HttpURLConnection connection = (HttpURLConnection)url.openConnection(); connection.connect(); int responseCode = connection.getResponseCode(); Log.i("Response Code", ""+responseCode); InputStream inputStream = connection.getInputStream(); Reader reader = new InputStreamReader(inputStream); BufferedReader r = new BufferedReader(reader); StringBuffer buffer = new StringBuffer(); String line ; while((line=r.readLine()) != null){ buffer.append(line + "\n"); } Log.i("ResponseData" , ""+buffer); jsonResponse = new JSONObject(buffer.toString()); JSONArray jsonPosts = jsonResponse.getJSONArray("posts") ; for(int i =0 ; i<jsonPosts.length() ; i++){ JSONObject jsonPost = jsonPosts.getJSONObject(i); String title = jsonPost.getString("title"); Log.i("Post"+i, title); } }catch (MalformedURLException ex){ Log.i(TAG , "Error Found ", ex); }catch(IOException ex){ Log.i(TAG , "Error Found ", ex); }catch (Exception ex){ Log.i(TAG , "Error Found ", ex); } return null ; } } }