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"


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM