A JSONObject is an unordered amassment of name/value pairs. Its external form is a string wrapped in curly braces with colons between the designations and values, and commas between the values and designations.
A JSONObject constructor can be acclimated to convert an external form JSON text into an internal form whose values can be retrieved with the get and opt methods, or to convert values into a JSON text utilizing the put and toString methods.
Example:
import org.json.simple.JSONObject;
class JsonEncodeDemo {
public static void main(String[] args){
JSONObject obj = new JSONObject();
obj.put("name", "abcd");
obj.put("salary", new Integer(100));
obj.put("balance", new Double(1000.21));
obj.put("vip", new Boolean(true));
System.out.print(obj);
}
}
Result would be
{"balance": 1000.21, "salary":100, "vip":true, "name":"abcd"}
0 Comment(s)