Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>My solution to parse a list of list of strings.</p> <pre><code>package stackoverflow.answers; import java.lang.reflect.Type; import java.util.List; import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; public class GsonTest { public static void main(String[] arg) { Gson gson = new Gson(); String jsonOutput = "[[\"-1.816513\",\"52.5487566\"],[\"-1.8164913\",\"52.548824\"]]"; Type listType = new TypeToken&lt;List&lt;List&lt;String&gt;&gt;&gt;() {}.getType(); List&lt;List&lt;String&gt;&gt; strings = (List&lt;List&lt;String&gt;&gt;) gson.fromJson(jsonOutput, listType); for(List&lt;String&gt; inner: strings){ for(String s: inner){ System.out.println(s); } } } } </code></pre> <p>But since values can be "thinked" also a doubles, you can parse them directly changing type into solution:</p> <pre><code>package stackoverflow.answers; import java.lang.reflect.Type; import java.util.List; import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; public class GsonTest { public static void main(String[] arg) { Gson gson = new Gson(); String jsonOutput = "[[\"-1.816513\",\"52.5487566\"],[\"-1.8164913\",\"52.548824\"]]"; Type listType = new TypeToken&lt;List&lt;List&lt;Double&gt;&gt;&gt;() {}.getType(); List&lt;List&lt;Double&gt;&gt; numbers = (List&lt;List&lt;Double&gt;&gt;) gson.fromJson(jsonOutput, listType); for(List&lt;Double&gt; inner: numbers){ for(Double d: inner){ System.out.println(d); } } } } </code></pre> <p>Not important in the context, but for future references: Java 7, Gson 2.2.4</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload