Method to convert JSON string into Map object

高洛峰
Release: 2016-12-03 14:35:48
Original
2391 people have browsed it

The page passes a json string to the background action, and the json string needs to be converted into a Map object

public Map toMap(Object object) { Map data = new HashMap(); // 将json字符串转换成jsonObject JSONObject jsonObject = JSONObject.fromObject(object); Iterator ite = jsonObject.keys(); // 遍历jsonObject数据,添加到Map对象 while (ite.hasNext()) { String key = ite.next().toString(); String value = jsonObject.get(key).toString(); data.put(key, value); } // 或者直接将 jsonObject赋值给Map // data = jsonObject; return data; }
Copy after login

The above method of converting a JSON string into a Map object is all the content shared by the editor.


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!