0
 spinner.setOnItemSelectedListener(new AdapterView.OnIte
 @Override                                          
 public void onItemSelected(AdapterView<?> parent, V
     if (position == 0) {                           

         title.clear();                             
         news_id.clear();                           
         date.clear();                              
         description.clear();                       
         img_url.clear();                           
         source_url.clear();                        
         category_to_fetch = "analysis";            
         getO(category_to_fetch);                   
     } else if (position == 1) {                    
         title.clear();                             
         news_id.clear();                           
         date.clear();                              
         description.clear();                       
         img_url.clear();                           
         source_url.clear();                        
         category_to_fetch = "blockchain";          
         getO(category_to_fetch);                   
     } else if (position == 2) {                    

         title.clear();                             
         news_id.clear();                           
         date.clear();                              
         description.clear();                       
         img_url.clear();                           
         source_url.clear();                        
         category_to_fetch = "exchanges";           
         getO(category_to_fetch);                   
     } else if (position == 3) {                    
         title.clear();                             
         news_id.clear();                           
         date.clear();                              
         description.clear();                       
         img_url.clear();                           
         source_url.clear();                        
         category_to_fetch = "general";             
         getO(category_to_fetch);                   
     } else if (position == 4) {                    

         title.clear();                             
         news_id.clear();                           
         date.clear();                              
         description.clear();                       
         img_url.clear();                           
         source_url.clear();                        
         category_to_fetch = "government";          
         getO(category_to_fetch);                   
     } else if (position == 5) {                    

         title.clear();                             
         news_id.clear();                           
         date.clear();                              
         description.clear();                       
         img_url.clear();                           
         source_url.clear();                        
         category_to_fetch = "ico";                 
         getO(category_to_fetch);                   
     } else if (position == 6) {                    

         title.clear();                             
         news_id.clear();                           
         date.clear();                              
         description.clear();                       
         img_url.clear();                           
         source_url.clear();                        
         category_to_fetch = "mining";              
         getO(category_to_fetch);                   
     }                                              


 }                                                  

 StringRequest stringRequest = new StringRequest(               
         Request.Method.GET,                                    
         Utils.CATEGORY, new Response.Listener<String>() {      
     @Override                                                  
     public void onResponse(String response) {                  
         try {                                                  
             Log.e("RESPONSE", response);                       

             JSONObject jsonObject = new JSONObject(response);  

             Log.e("OBJECT", jsonObject.toString());   

LOGCAT

THIS IS THE STRING RESPONSE

E/RESPONSE: {"analysis":[// RESPONSE

AFTER CONVERTING IT TO JSONOBJECT IT IS SHOWING DATA LIKE BELOW E/OBJECT: {"exchanges" :[// RESPONSE

WHEN I CHOOSE ANALYSIS CATEGORY FROM SPINNER DATA IS LOADED

WHEN I CHOOSE ANALYSIS CATEGORY FROM SPINNER DATA IS ICO

WHEN I CHOOSE ANALYSIS CATEGORY FROM SPINNER DATA IS MINING

else

DATA IS NOT LOADED EVEN THOUGH I HAVE THE DATA

2 Answers2

0

JSON properties are not ordered. It shouldn't bother you if they're suddenly displayed in a different order before and after parsing.

kumesana
  • 2,495
  • 1
  • 9
  • 10
  • But I have to fetch data according to the JSONObject ..this is not working – Xay Programming Jul 09 '18 at 07:38
  • @XayProgramming this is not a contest to use as few words as possible. Be specific. Show the JSON you have at various stages, with at least a bunch of lines and not just one word. Preferably show what you're interested in this JSON. Then show the code you have to try and make use of this JSON. Then explain what you obtain and what you wanted to obtain instead. – kumesana Jul 09 '18 at 07:41
  • I have explained the issue in detail please see my question – Xay Programming Jul 09 '18 at 07:46
  • @XayProgramming there are zero details in your question. I have told you the kind of details you need to give. First give them, then we'll see if you get to claim you gave details. – kumesana Jul 09 '18 at 07:51
  • EDITED QUESTION SEE ABOVE – Xay Programming Jul 09 '18 at 08:00
  • @XayProgramming You're still not showing the JSON in full, you're showing the first word and nothing else. Why? You're still not showing what you're doing with the JSON. I told you to. We don't know of a spinner. You could have made it all clearer. And caps are useless. – kumesana Jul 09 '18 at 08:04
0

if you use retrofit use HttpLogginInterceptor this interceptor which logs request and response information: add gradle :

implementation 'com.squareup.okhttp3:logging-interceptor:3.6.0'

and add .addInterceptor(interceptor)

HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY);

OkHttpClient client = new OkHttpClient.Builder()
                .readTimeout(60, TimeUnit.SECONDS)
                .connectTimeout(60, TimeUnit.SECONDS)
                .writeTimeout(60, TimeUnit.SECONDS)
                .addInterceptor(interceptor)
                .cookieJar(new JavaNetCookieJar(cookieHandler))
                .build();

and if you want to print response use GSON converter :

//print respone
Log.e(" Full json gson => ", new Gson().toJson(response));

JSONObject jsonObj = new JSONObject(new Gson().toJson(response).toString());
                        Log.e(" responce => ", jsonObj.getJSONObject("body").toString());

check my ans here

Adil
  • 812
  • 1
  • 9
  • 29