A JSON Object can be created using Java very easily using any JSON library.
We are using JSON-Simple.jar to build/parse the JSON Object using Java.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
import org.json.simple.JSONObject; class JSONBuilder { public static void main(String[] args){ JSONObject jsonObject = new JSONObject(); jsonObject.put("names", "testjsonuser3"); jsonObject.put("action", "IllustrateJSONObjectInScript"); jsonObject.put("logincount", "3"); System.out.print(jsonObject); } } |
Results:
{“names”:”testjsonuser3″,”actions”:”IllustrateJSONObjectInScript”,”logincount”:3}
We could see the result displays the JSON Object., and it has string field printed with double quotes.
The java Object is created with only name value pairs in jsonObject field.