java类转换json

package com.didi.haitangwan.sc.meta.dal;
import com.alibaba.fastjson.JSONObject;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

public class Test {

        private String RESULT_CODE;
        private String RESULT_VALUE;

        public String getRESULT_CODE() {
            return RESULT_CODE;
        }
        public void setRESULT_CODE(String rESULT_CODE) {
            RESULT_CODE = rESULT_CODE;
        }
        public String getRESULT_VALUE() {
            return RESULT_VALUE;
        }
        public void setRESULT_VALUE(String rESULT_VALUE) {
            RESULT_VALUE = rESULT_VALUE;
        }
        /**
        *{"data":[{"updated_at":"1971-01-01 00:00:00","rght":"728","tree_id":"36","level":"1","parent_id":"0","name":"全国","created_at":"1971-01-01 00:00:00","taxi_id":"0","id":"212962","lft":"1","aid":"","cityId":0},{"updated_at":"1971-01-01 00:00:00","rght":"6","tree_id":"36","level":"3","parent_id":"212962","name":"北京市","created_at":"1971-01-01 00:00:00","taxi_id":"1","id":"212964","lft":"5","aid":"","cityId":1}
        **/
        public static void main(String[] args) {
            Test result = new Test();
            result.setRESULT_CODE("0");
            result.setRESULT_VALUE("OK");
            Test result1 = new Test();
            result1.setRESULT_CODE("0");
            result1.setRESULT_VALUE("OK");
            ArrayList list= new ArrayList();
            list.add(result);
            list.add(result1);
            Map testMap = new HashMap();
            testMap.put("data:",list);
            String resultJson = JSONObject.toJSONString(testMap);
            System.out.println(resultJson);
        }
    }


你可能感兴趣的:(JAVA)