We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello
I'm trying to learn the JSON and it's intricacies.
I'm using the JSONget example as a starter.. I want to do conditionnals, but it never returns true.
Even using the debugger, it all seem ok and the same, t and a will give type java.lang.String = "Wilbert"
what am I missing here? I'm confused..
Thanks for the help
---- CODE --
import http.requests.*;
public void setup()
{
size(100,100);
smooth();
GetRequest get = new GetRequest("http://connect.doodle3d.com/api/list.example");
get.send(); // program will wait untill the request is completed
println("response: " + get.getContent());
JSONObject response = parseJSONObject(get.getContent());
println("status: " + response.getString("status"));
JSONArray boxes = response.getJSONArray("data");
println("boxes: ");
for(int i=0;i<boxes.size();i++) {
JSONObject box = boxes.getJSONObject(i);
String t = box.getString("wifiboxid");
String a = "Wilbert";
println("t : "+ t); //confirms the name to compare
println(t.length()); // confirms length, so no extra characters
println(a.length()); // confirms length, so no extra characters
if ( t == a) // compare but never true
{
println(" wifiboxid: " + box.getString("wifiboxid"));
println(" remoteip: " + box.getString("remoteip"));
}
}
}
---- JSON -----
http://connect.doodle3d.com/api/list.example
{
"status":"success",
"data":[
{
"id":"62.216.8.197\/10.0.0.18",
"remoteip":"62.216.8.197",
"localip":"10.0.0.18",
"wifiboxid":"Albert",
"hidden":"0",
"date":"2013-10-03 17:24:33",
},
{
"id":"62.216.8.197\/10.0.0.29",
"remoteip":"62.216.8.197",
"localip":"10.0.0.29",
"wifiboxid":"Wilbert",
"hidden":"0",
"date":"2013-10-03 17:52:19"
}
],
}
Answers
https://Processing.org/reference/String_equals_.html
WOW! that was fast!
Thanks @GoToLoop!!
Just wondering.. I tried before posting
And it worked.. but for
.. wich looks the same to me I have to do
the site tells " This method is necessary because it's not possible to compare strings using the equality operator (==) " but still t==t works..
any idea why exactly?
thanks!
... found some explanation... here
LeePoint.net
and here
StackOverflow
Looks like it has to do with objects..
==
&!=
over reference types, what we're actually comparing is their memory addresses, not their content.""
String objects.==
&!=
, besides equals().thanks for the "to the point" explanation...