Java将String转换成json对象或json数组

这里的SmartProejctEquipmentMap 是我自定的一个实体类,可以自己定义转换。

注意:json字符串中键的名称要和实体类一致。

@Test
    public void TestJsonObject() {
        String datajson = "" +
                "[" +
                "   {" +
                "       'projectId':'00a8de32-422c-4b8d-b945-d9cda7f30a31'," +
                "       'projectName':'年产片式元器件7.2亿个、高分子固体电容器3.96亿个等项目(标准厂房、连廊A,甲类仓库,办公楼,宿舍,值班门卫,垃圾房)'," +
                "       'iconType':'yc'," +
                "       'eqpType':'yc'," +
                "       'sn':'SZWJJJ8MQX20200403134027'," +
                "       'name':'测试第三方01'," +
                "       'wkt':'测试第三方01'," +
                "       'sn':'POINT(120.698299 31.272362)'" +
                "   }," +
                "   {" +
                "       'projectId':'00a8de32-422c-4b8d-b945-d9cda7f30a31'," +
                "       'projectName':'测试项目编号名称'," +
                "       'iconType':'yc'," +
                "       'eqpType':'yc'," +
                "       'sn':'FDASDFAFDAFYF89AS6F897DD'," +
                "       'name':'扬尘设备001'," +
                "       'wkt':'扬尘设备001'," +
                "       'sn':'POINT(120.698299 31.272362)'" +
                "   }" +
                "]";

        JSONArray jsonArray = JSONArray.parseArray(datajson);
        for(int i=0; i

你可能感兴趣的:(Java)