0

The service returns json in the following format :

    [
    "ABC",
    "HELLO",
    "GOODBYE"
    ]

How can I count the number of strings inside the json?

worrynerd
  • 705
  • 1
  • 12
  • 31

1 Answers1

0

You can use a Json parser like GSON, to deserialize the JSON.

// Deserialization
int[] ints2 = gson.fromJson("[1,2,3,4,5]", int[].class); 
// ==> ints2 will be same as ints
System.out.println(int2.length);

see https://github.com/google/gson/blob/master/UserGuide.md#TOC-Array-Examples

Chol Nhial
  • 1,327
  • 1
  • 10
  • 25
  • `String[] myList = gson.fromJson("[\"one\", \"two\", \"three\"]", String[].class)` I believe that would be how to deserialize a list of strings – Chol Nhial Aug 28 '17 at 22:46