简体   繁体   中英

Having problems in making JSONObjects in Java

my code to make my JSONObject is basically:

InputStream instream = entity.getContent();

// Load the requested page converted to a string into a JSONObject.  
JSONObject myAwway = new JSONObject(convertStreamToString(instream));  

// Get the query value'  
String query = myAwway.getString("data");  

// Make array of the suggestions  
JSONArray suggestions = myAwway.getJSONArray("data");  

This was working perfectly fine until a couple of minutes ago, when suddenly, it gives me the error "JSON failed"... any idea why?

You have:

 String query = myAwway.getString("data");  
 JSONArray suggestions = myAwway.getJSONArray("data");  

Wouldn't that mean that the item "data" of your Object is a String AND an array? That might be possible as long as its empty, so it might have worked (don't now this for sure). But it doesn't seem very right to get a String and a JSONArray from the same place.

  • print out your convertStreamToString(instream) string. Does that give you a valid json string?
  • if so, what's in there.. is the 'data' a string or an object?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM