Note that there are some explanatory texts on larger screens.

plurals
  1. POadd item to a local json file using javascript object / java code
    text
    copied!<p>I have a locally stored json file as c:\path\jsontext.json. I have a jsp page and .js file, In my .js file I have a javascript object, the data of this javascript object is in json format and i would like to append it to the jsontext.json file</p> <p>But can figure out a way to do this.</p> <p>Here is my jsontext.json</p> <pre><code>[ { "Identifier": "1", "Label": "pratik", "Categories": "Standard", "UpdatedBy": "lno", "UpdatedAt": "01-02-2013" }, { "Identifier": "2", "Label": "2013", "Categories": "Standard", "UpdatedBy": "lno", "UpdatedAt": "01-02-2013" } ] </code></pre> <p>supposing in my .js file i have a javascript object </p> <pre><code>var JSObject=("[{" +'"example1"'+"},"+ "{" + '"example2"' + "}]"); </code></pre> <p>I want to append this data in my jsontext.json file, </p> <p>how should I go about it. </p> <p>I looked at some resources and found that I would require a server side programming language to get this done. </p> <p>If I try doing this in a java code, then the code is easy to write. The only problem then is the java method will be execute first and then the .js file. </p> <p>If there is a way - a clickevent on the .js file which can call the java method then it would also work for me. </p> <p>I have this java code. </p> <pre><code>import java.io.FileWriter; import java.io.IOException; import org.json.simple.JSONArray; import org.json.simple.JSONObject; public class JsonSimpleExample { public static void main(String[] args) { JSONObject JSONObject = new JSONObject(); try { FileWriter file = new FileWriter("c:\\jsontext.json"); file.write(JSONObject.toJSONString()); file.flush(); file.close(); } catch (IOException e) { e.printStackTrace(); } System.out.print(JSONObject); } } </code></pre> <p>Where should I include this java code in order to write the item into jsontext.json file.? and. IS there are method in Jquery for this??</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload