Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • JSON with JAVA

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 199
    Comment on it

    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)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: