Java: parse Array of Arrays from JSON

后端 未结 1 1990
再見小時候
再見小時候 2021-01-27 07:53

I have a JSON Arrays of Array like this

{
    \"width\" : 500,
    \"numbers\" : [ 
        [46, 11, \"1674\"],
        [46, 11, \"1673\"],
        [46, 11, \"16         


        
相关标签:
1条回答
  • 2021-01-27 08:38

    Try GSON, the following should do the trick:

    import java.io.File;
    import java.io.IOException;
    import org.apache.commons.io.FileUtils;
    import com.google.gson.Gson;
    
    public class ReadTest {
    
    public static void main(String[] args) throws IOException {
        String json = FileUtils.readFileToString(new File("json.txt"));
    
        Gson gson = new Gson();
    
        A a = gson.fromJson(json, A.class);
    
        System.out.println(a.width);
        System.out.println(a.numbers[0][0]);
        }
    }
    
    
    public class A {
        public int width;
        public int numbers[][];
    }
    
    0 讨论(0)
提交回复
热议问题