Android Map转换为JSON

HashMap<String, Object> headers = new HashMap<String, Object>();
headers.put("User-Agent", "Android");
headers.put("Content-Type", "application/json");

Map map = new HashMap();
map.put("success", "true");
map.put("photoList", "ssss");
map.put("currentUser", "zhang");

JSONObject json =new JSONObject(map);
JSONObject json2 =new JSONObject(headers);
LgqLogutil.e("llll----"+json+"....."+json2);

E/lgq: httpheader----llll----{"photoList":"ssss","currentUser":"zhang","success":"true"}.....{"User-Agent":"Android","Content-Type":"application\/json"}

2、建值

Map map = new HashMap();
map.put("success", "true");
map.put("photoList", "ssss");
map.put("currentUser", "zhang");

JSONObject jsonObject = new JSONObject();
jsonObject.put("name",map);

 E/lgq: httpheader----..222....{"name":"{photoList=ssss, currentUser=zhang, success=true}"}

2、

/**
 * 将JavaBean序列化为JSON文本
 *
 * @param object
 * @return
 */
public static String toJSONString(Object object) {
    return JSON.toJSONString(object);
}
发布了339 篇原创文章 · 获赞 66 · 访问量 36万+

猜你喜欢

转载自blog.csdn.net/meixi_android/article/details/92791363