Encode and Decode JSON text from Java to JavaScript – Using List

JSON.simple is a simple Java toolkit for JSON. You can use JSON.simple to encode or decode JSON text.

  1. Mapping between JSON and JAVA entities: 
    JSON Java
    string java.lang.String
    number java.lang.Number
    true|false java.lang.Boolean
    null null
    array java.util.List
    object java.util.Map
  2. Example:
    //import org.json.simple.JSONObject;
    Encode a java.util.List in Java

      JSONObject obj = new JSONObject();
      obj.put("num",new Integer(100));
      obj.put("balance",new Double(1000.21));
      obj.put("is_vip",new Boolean(true));
      String jsonText = JSONValue.toJSONString(obj);

    Decode it in JavaScript using JSONObject


      var js_obj = JQuery.parseJSON(jsonText);
      var name = js_obj[0].name;
      var num = js_obj[0].num;

Reference Link: https://code.google.com/p/json-simple/
Reference Link: http://api.jquery.com/jQuery.parseJSON/
Reference Link: http://www.jquerysdk.com/api/jQuery.toJSON

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s