如何将字符串数组转换为json数组

时间:2019-05-31 12:12:15

标签: java json jackson

我想转换下面的由objectmapper读取值形成的String数组

[{"name"="", "isfirstname"="false", "lastname"="",  "createdate"="2018-09-05 20:16:07", "address1"="", "hold_reason"="", "address2"="", "number"="abcd001"}]
Passing the above json to the below method it returns map

    public static Map<String, Object> jsonToMap(String jsonString) {
        ObjectMapper mapper = new ObjectMapper();
        Map<String, Object> map = new HashMap<String, Object>();
        // convert JSON string to Map
        if (jsonString == null) {
            return map;
        }
        try {
            map = mapper.readValue(jsonString, HashMap.class);
        } catch (IOException e) {

        }
        return map;

}

and the output is 
[{name=, isfirstname=false, lastname=,  createdate=2018-09-05 20:16:07, address1=, hold_reason=, address2=, number=abcd001}]
Now converted the output to string then result is [{name=, isfirstname=false, lastname=,  createdate=2018-09-05 20:16:07, address1=, hold_reason=, address2=, number=abcd001}]
Now I want to parse this String to json array as original which means like this
[{"name"="", "isfirstname"="false", "lastname"="",  "createdate"="2018-09-05 20:16:07", "address1"="", "hold_reason"="", "address2"="", "number"="abcd001"}]

0 个答案:

没有答案