1

I am trying to parse JSON using GSON library, but I am having some issues.

The problem is that some of the keys can contain double and String values. Here is an example:

"message":"unlimited"

But this can also be:

"message":4.0

Can anyone help me to find a solution for this?

HaveNoDisplayName
  • 8,291
  • 106
  • 37
  • 47
DPE
  • 218
  • 5
  • 15

2 Answers2

0

You can create a custom type for your message field, and implement a TypeAdapter for it.

user3707125
  • 3,394
  • 14
  • 23
0
 Object aObj = jObj.get("message");

            if (aObj instanceof Double) {
               Log.d("Oobjext",":" + aObj);

            }else if(aObj instanceof String){
                Log.d("Oobjext string",":" + aObj);
            }

Most of the times, server should not be doing this. Because checking the type of "key" will be a hectic task.

m0rpheu5
  • 600
  • 4
  • 16