-
How to Parse and read the JSON Array using GSON library
about 9 years ago
-
about 9 years ago
Modal Class
package com.example.amitrai.internettest; import java.io.Serializable; /** * Created by amitrai on 28/9/15. */ public class Modalone implements Serializable { String id, displayLabel, name, fieldType, mandatory, editable, description, options, Bug, Feature,Enhancement; public String getId() { return id; } public void setId(String id) { this.id = id; } public String getDisplayLabel() { return displayLabel; } public void setDisplayLabel(String displayLabel) { this.displayLabel = displayLabel; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getFieldType() { return fieldType; } public void setFieldType(String fieldType) { this.fieldType = fieldType; } public String getMandatory() { return mandatory; } public void setMandatory(String mandatory) { this.mandatory = mandatory; } public String getEditable() { return editable; } public void setEditable(String editable) { this.editable = editable; } public String getDescription() { return description; } public void setDescription(String description) { this.description = description; } public String getOptions() { return options; } public void setOptions(String options) { this.options = options; } public String getBug() { return Bug; } public void setBug(String bug) { Bug = bug; } public String getFeature() { return Feature; } public void setFeature(String feature) { Feature = feature; } public String getEnhancement() { return Enhancement; } public void setEnhancement(String enhancement) { Enhancement = enhancement; } }
Modal class Two
package com.example.amitrai.internettest.modal; import java.io.Serializable; /** * Created by amitrai on 28/9/15. */ public class Modaltwo implements Serializable { public String id, displayLabel, name,fieldType, mandatory, editable, description; public String getId() { return id; } public void setId(String id) { this.id = id; } public String getDisplayLabel() { return displayLabel; } public void setDisplayLabel(String displayLabel) { this.displayLabel = displayLabel; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getFieldType() { return fieldType; } public void setFieldType(String fieldType) { this.fieldType = fieldType; } public String getMandatory() { return mandatory; } public void setMandatory(String mandatory) { this.mandatory = mandatory; } public String getEditable() { return editable; } public void setEditable(String editable) { this.editable = editable; } public String getDescription() { return description; } public void setDescription(String description) { this.description = description; } }
parsing code
// parsing data with gson private void parseData(){ try { JSONArray jsonArray = new JSONArray(response); JSONObject obj = jsonArray.getJSONObject(0); JSONObject obj_two = jsonArray.getJSONObject(1); Gson gson = new Gson(); Modaltwo gsonObj = gson.fromJson(obj.toString(), Modaltwo.class); Modalone modalone = gson.fromJson(obj_two.toString(), Modalone.class); Log.e("response", ""+gsonObj); Log.e("response", ""+modalone); } catch (Exception e) { e.printStackTrace(); } }
Happy codeing.
-
1 Answer(s)