6

JSONArray.getString(1); where ["name",null] is the json array, throws a JSONArray[1] not a string exception only when proguard is enabled.

Am I missing something in my proguard rules?

W4R10CK
  • 5,502
  • 2
  • 19
  • 30

1 Answers1

0

Did you try these methods:

/**
 * Returns the value at {@code index} if it exists, coercing it if
 * necessary. Returns the empty string if no such value exists.
 */
public String optString(int index)

or

/**
 * Returns the value at {@code index} if it exists, coercing it if
 * necessary. Returns {@code fallback} if no such value exists.
 */
public String optString(int index, String fallback)

Seem like does not return null for String

Tam Huynh
  • 2,026
  • 1
  • 16
  • 20
  • Yes I have, they do work. But the existing project has getString all over.. Switching to optString is the last option. – Poyyamozhi Ramakrishnan Feb 07 '20 at 03:45
  • By reading the code of `public String getString(int index)`, I can see it throws exceptions if your value is null and currently your input has null value. If you didn't catch the exception everywhere `getString` is used then bugs will keep appearing. Change the method is a hard but safe way – Tam Huynh Feb 07 '20 at 04:06