java fastjson 的测试

    public static String ReadFile(String Path){
        BufferedReader reader = null;
        String laststr = "";
        try{
            FileInputStream fileInputStream = new FileInputStream(Path);
            InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream, "UTF-8");
            reader = new BufferedReader(inputStreamReader);
            String tempString = null;
            while((tempString = reader.readLine()) != null){
                laststr += tempString;
            }
            reader.close();
        }catch(IOException e){
            e.printStackTrace();
        }finally{
            if(reader != null){
                try {
                    reader.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        return laststr;
    }

    @Test
    public void testGet() {
        try {
            String filePath = "d:\\\\game.json";
            String jsonContent = ReadFile( filePath );

            JSONObject root = new JSONObject().parseObject(jsonContent);
            JSONObject sub = root.getJSONObject("data");
            if ( sub != null ) {
                JSONArray array = (JSONArray) sub.get("allStarSkillMatchPlayerInfos");
                for (int i = 0; i < array.size(); i++)
                {
                    String post_id = ((JSONObject)array.get(i)).get("playerId").toString();
                    int a = 0;
                }
            }

 

你可能感兴趣的:(spring,boot,java)