How google gson library can be used to parse given below json

后端 未结 2 718
盖世英雄少女心
盖世英雄少女心 2021-01-22 23:10

I have this JSON

{
    \"309\":{ \"productId\":309,  \"name\":\"Heat Gear Polo\"},
    \"315\":{ \"productId\":310,  \"name\":\"Nike\"},
    \"410\":{ \"productI         


        
2条回答
  •  温柔的废话
    2021-01-22 23:53

    public static void main(String[] args)
    {
        try
        {
            Gson gson = new Gson();
    
            String json = "{\"309\":{ \"productId\":309,  \"name\":\"Heat Gear Polo\"},\"315\":{ \"productId\":310,  \"name\":\"Nike\"},\"410\":{ \"productId\":311,  \"name\":\"Armani\"}}";
            Type type = new TypeToken>(){}.getType();
            Map myMap = gson.fromJson(json, type);
            System.out.println(myMap);
        }
        catch (Exception e)
        {
            // TODO: handle exception
        }
    }
    

提交回复
热议问题