Json的相关操作

1,将Json字符串转化为Json

try {
	 try {
        Gson gson = new Gson();
		MessageModle msg = gson.fromJson(responceData, MessageModle.class);
	 } catch (JsonSyntaxException var4) {
        throw new JsonFormatException(var4);
   	 }
} catch (JsonFormatException e) {
    e.printStackTrace();
}

2, 将hashMap转换为Json字符串

Map<String, Strig> param = new Hashmap<>();
Param.put(“userName”, “xiaoming”);
Gson gson = new Gson();
String request = gson.toJson(param);
发布了48 篇原创文章 · 获赞 27 · 访问量 3万+

猜你喜欢

转载自blog.csdn.net/weixin_41480546/article/details/88991769