---
title: "Gson解析json字符串到Map<String, Object>"
author: "z610"
date: "2012-09-02T08:58:29Z"
tags: []
categories: ["编程语言"]
slug: "gson-json-map-string-object"
draft: false
lastmod: "2012-09-02T09:00:40Z"
id: 1669622
url: "https://z610.iteye.com/blog/1669622"
---

```
public class TmpTest {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		final Map<String, Object> map = new LinkedHashMap<String, Object>();
		map.put("a", 1);
		map.put("b", "a");
		map.put("c", 2);
		final Gson gson = new Gson();
		final String string = gson.toJson(map);
		final Type type = new TypeToken<Map<String, Object>>() {}.getType();
		final Map<Object, Object> map2 = gson.fromJson(string, type);
		for (final Entry<Object, Object> entry : map2.entrySet()) {
			System.out.println(entry.getKey() + " : " + entry.getValue());
		}
	}

}
```