Gson parse Json with array

后端 未结 1 689
感情败类
感情败类 2021-01-22 18:33

I am having some trouble building a class which will parse out gson as I expect it to.

I created a class.

public class JsonObjectBreakDown {
    public         


        
相关标签:
1条回答
  • 2021-01-22 19:25

    The problem here is that you have an array of arrays of arrays of floating point numbers in your JSON. Your class should be

    public class JsonObjectBreakDown {
        public String type; 
        public List<List<float[]>> coordinates = new ArrayList<>();
    }
    

    Parsing with the above and trying

    System.out.println(p.coordinates.size());
    System.out.println(p.coordinates.get(0).size());
    System.out.println(Arrays.toString(p.coordinates.get(0).get(0)));
    

    yields

    1
    2
    [-66.9, 18.05]
    
    0 讨论(0)
提交回复
热议问题