今天把Android Studio 升級到4.1版本,發(fā)現(xiàn)GsonFormat沒有了,網(wǎng)上有的解決辦法從https://plugins.jetbrains.com/plugin/7654-gsonformat下載jar包,本地安裝插件,試了報Plugin “GsonFormat” is incompatible (supported only in IntelliJ IDEA)。 最后,把jar刪除,從marketplace安裝了GsonFormatPlus。 會有兩個問題 1.顯示...
Gsongson =new Gson(); User user = new User(123,"zy"); //將對象轉(zhuǎn)為json字符串 String str = gson.toJson(user); //再由json字符串轉(zhuǎn)為java對象,通過get方法得到對象里的值 User fromJson = gson.fromJson(str, User.class); System.out.println(fromJson.getAge()+"..."+fromJson.getName...
return new Gson().toJson(response); } } /** * 客戶端 */ public class Client { public static void getPerson(){ String responseStr = Server.getPersonById(1234L); //反序列化 Response<PersonInfo> response = new Gson().fromJson(responseStr, new TypeToken<Response<PersonInfo>>(){}.getTyp...