package com.hxhq.business.utils;

import com.alibaba.fastjson2.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
/**
 * @author tanfei
 */
public class JctUtil {
    private static final Logger LOG = LoggerFactory.getLogger(JctUtil.class.getName());

    public static void main(String[] args) {
        Map<String, String> formData = new LinkedHashMap<>();
        formData.put("姓名", "张三");
        formData.put("年龄", "19");
        LOG.info(formatStr(formData));
    }

    public static String formatStr(Map<String, String> map) {
        List<Jcgj> result=new ArrayList<>();
        // 遍历键值对
        for (Map.Entry<String, String> entry : map.entrySet()) {
            String key = entry.getKey();
            String value = entry.getValue();
            Jcgj jcgj=new Jcgj();
            jcgj.setName(key);
            jcgj.setValue(value);
            result.add(jcgj);
        }
        return JSONObject.toJSONString(result);
    }

    public static class Jcgj {
        private String name;
        private String value;

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public String getValue() {
            return value;
        }

        public void setValue(String value) {
            this.value = value;
        }
    }
}
