Gson应用:从json格式简单字符串中获取value
1 import java.io.ByteArrayInputStream; 2 import java.io.IOException; 3 import java.io.InputStreamReader; 4 import java.io.UnsupportedEncodingException; 5 6 import com.google.gson.JsonElement; 7 import com.google.gson.JsonObject; 8 import com.google.gson.JsonParser; 9 import com.google.gson.stream.JsonReader; 10 11 public class GsonTest { 12 13 public static void main(String[] args) { 14 String sgson="{\"token\":\"3e860808205f4a128c4cafe9651fd924\",\"memberId\":\"90000016\",\"memberNo\":\"90000016\"}"; 15 JsonElement je = new JsonParser().parse(sgson); 16 System.out.println(je.isJsonObject()); 17 System.out.println(je.getAsJsonObject().get("token")); 18 } 19 20 }
输出:
true
"3e860808205f4a128c4cafe9651fd924"
本文来自博客园,作者:月色深潭,交流群:733423266,转载请注明原文链接:https://www.cnblogs.com/moonpool/p/6879326.html