One bad person wrote me a PHP web service that gives me phone numbers. Why bad - because he sends me in this form:

[77012260000,77012260001,77012260002,77012260003,77012260004,77012260005,77012260006,77012260007]. 

How do I throw it in a List or an array (raspit)?

I sit and can not understand, like JSON and it seems not. I can’t catch him to force him to rewrite.

    3 answers 3

    Without a dot at the end of the line, this is a perfectly valid JSON.

    Outside - an array (array), the elements of the array (value) - numbers (number).

    Jackson parsing example:

     String json = "[77012260000,77012260001,77012260002,77012260003,77012260004,77012260005,77012260006,77012260007]"; ObjectMapper mapper = new ObjectMapper(); List list = mapper.readValue(json, List.class); System.out.println(list); // [77012260000, 77012260001, 77012260002, 77012260003, 77012260004, 77012260005, 77012260006, 77012260007] 

      There is no problem:

      1. We remove too much

         String s = "[77012260000,77012260001,77012260002,77012260003,77012260004,77012260005,77012260006,77012260007]."; s = s.subString(1, s.indexOf("]")); 
      2. We divide into an array by comma:

         String[] array = s.split(","); 

        I would do it through gson

         Type listType = new TypeToken<ArrayList<Long>>() {}.getType(); List<Long> yourClassList = new Gson().fromJson(jsonString, listType);