Instagram's JSONObject crash

edited July 2015 in Questions about Code

Hi all. I've been doing some stuff with Instagram's JSON file and seem to hit a wall. I have this function getImageFromJSON() and nodes is my Instagram object that receives the image, username and text from instagram pictures

jsonAgram = loadJSONObject(urlSearch); 
... 
void getImageFromJSON() {
  JSONArray instagramData = jsonAgram.getJSONArray("data");
  JSONObject entry = instagramData.getJSONObject(counter);
  JSONObject image1Data = entry.getJSONObject("images").getJSONObject("thumbnail");
  JSONObject username=entry.getJSONObject("user");
  JSONObject texto=entry.getJSONObject("caption");

  imageURL = image1Data.getString("url");
  instaUser = username.getString("username");
  instaText = texto.getString("text","");
  //instaText="";
  img = loadImage(imageURL);

  nodes.add(new Node(img, instaText, instaUser));
}

when there's no caption, i get JSONObject["caption"] is not a JSONObject when there's no text, instagram sets caption as null, so i'm trying to get a null test done. first i set texto as an empty JSONObject and then populate it depending on the result from the reading of the original JSON

 JSONObject texto=new JSONObject()
 if (entry.getJSONObject("caption").isNull("text")) {
   entry.setJSONObject("",texto).setString("text","");
 } else{
   texto=entry.getJSONObject("caption");
 }

well, actually it's not working. can anybody give me any idea on what's worng? tks

Answers

Sign In or Register to comment.