Hello. There are already 3,000,000,000 such questions here. But I don’t understand how to take and learn how to serialize / deserialize Json using GSON.
There is an answer from the server like:
`{"p_result":"ok"}` This is an object of type Json, not an array, not anything else.
I need to get this very "ok".
I also have an example of working code, getting values from an array:
User.java public class User { private String p_id; private String p_name; private String p_last_name; public String getId() { return p_id; } public void setId(String id) { this.p_id = id; } public String getName() { return p_name; } public void setName(String name) { this.p_name = name; } public String getLastName() { return p_last_name; } public void setLastName(String lastName) { this.p_last_name = lastName; } } To him:
public class JsonWorker { public static List<User> jsonToUserList(String json) { Gson gson = new Gson(); Type listType = new TypeToken<List<User>>() {}.getType(); return gson.fromJson(json,listType); } } And method:
public static List<User> getUserFromServer() throws IOException, JSONException { final List<NameValuePair> nameValuePairList = new ArrayList<NameValuePair>(); nameValuePairList.add(new BasicNameValuePair("query", "spr_employee_get")); nameValuePairList.add(new BasicNameValuePair("p_guid", user_guid)); final String resp = execHttpGet(url, nameValuePairList); JSONObject jsonObject = new JSONObject(resp); if (jsonObject.has("p_result")) { if (jsonObject.getString("p_result").equalsIgnoreCase("ok")) return JsonWorker.jsonToUserList(jsonObject.getJSONArray("p_item").toString()); } return new ArrayList<User>(); } And I, even by analogy, cannot do ...