Item.java
JSONObject json = new JSONObject();
private String value;
private String type;
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String toString() {
json.put(value, type);
return json.toString();
}
Bean.java
@PostConstruct
public void init() {
items=new JSONArray();
}
public void add() throws ParseException {
items.add(new Item());
}
public void remove(Item item) {
items.remove(item);
}
public void save() {
System.out.println("JsonSchema "+items);
}
public JSONArray getItems() {
return items;
}
While retrieving json from Sample.java in Bean.java - I get the output of this format -
[{"id":"number"},{"name":"text"},{"type":"number"}]
I want to convert this to JSONObject of below format using JsonSimple library-
{"id":"number","name":"text","type":"number"} //convert to this format
I am just a beginner. Any help would be appreciated. Thank you in advance.