We are about to switch to a new forum software. Until then we have removed the registration on this forum.
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
Might help to show what the Json data looks like.
PhiLho, it's the usual instagram JSON
this is the populated caption. had to edit because it won't fit
this is the null data on the JSON
http://forum.Processing.org/two/discussion/11742/how-to-deal-with-null-variables-in-json-file
i've seen that, GoToLoop. The default value crashed anyway, unless I set it wrong(might be the case). I used it in setString(key, default), so I must use it in the getString(key, default)?
as stated above, instaText has the two values: ("text","")
Seems like JSONObject doesn't have support to set its entries w/
null
! :-qwell, it looks lihke after a few years I can have my first bug report to processing...
fixed at last
Oh, long time! :-h Glad you've finally made it. <:-P
But I wonder how recent is that isNull() method? :P
https://Processing.org/reference/JSONObject_isNull_.html
can you post the entire code?
all the data that i push is hard data except the picture caption, so i had to have a check for the availability of the JSONObject.
i was updating the code today since instagram changed the rules and accesses to the api.