package com.mandi.system.test;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
public class zjwTest {
public static void main(String[] args) {
String jsonStr = "{" + "'title':'get_msg_setting_info',"
+ "'groupList':[{'ses_id':'F9E0147B-3444-413F-A568-C2D49464CCFB'},{'ses_id': '2b694b46-b839-4364-905f-b352651c53a9'}],"
+ "'my_ip':'112.95.153.98'" + "}";
JsonObject jObject = new JsonParser().parse(jsonStr).getAsJsonObject();
// title : 字符串
String title = jObject.get("title").getAsString();
System.out.println("title:" + title);
// groupList : List集合
JsonArray array = jObject.get("groupList").getAsJsonArray();
for (JsonElement jsonElement : array) {
JsonObject jo = jsonElement.getAsJsonObject();
String ses_id = jo.get("ses_id").getAsString();
System.out.println("ses_id:" + ses_id);
}
// my_ip : 字符串
String my_ip = jObject.get("my_ip").getAsString();
System.out.println("my_ip:" + my_ip);
}
}
网友评论