0

I try to compare the result of an asynchronous function as below:

WritableMap res;
res = ServerAuthenticate.signIn(userName, userPass);

Log.d(TAG, " --> res.getString(status).length(): " + res.getString("status").length());
Log.d(TAG, " --> res.getString(status): " + res.getString("status"));
Log.d(TAG, " --> res.getString('status') == 'OK': " + (res.getString("status") == "OK"));

The code of above gives the following console outputs:

D/!NativeModules( 5899): --> res.getString(status).length(): 2
D/!NativeModules( 5899): --> res.getString(status): OK
D/!NativeModules( 5899): --> res.getString('status') == 'OK': false

res.getString("status") value is OK string but when I put it to a comparison as res.getString("status") == "OK" it returns false. Actually I use the method of results.putString("status", "OK"); in ServerAuthenticate.signIn() function.

I wonder if is there any way to compare a property value of a WritableMap?

codewitharefin
  • 1,398
  • 15
  • 24
efkan
  • 12,991
  • 6
  • 73
  • 106

1 Answers1

1

This is the standard Java String equals problem. Try res.getString("status").equals("OK") or for better null safety "OK".equals(res.getString("status")).

See also Java String.equals versus ==

Leonard Brünings
  • 12,408
  • 1
  • 46
  • 66