Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to save the JSON data to the database
    primarykey
    data
    text
    <p>I am trying to save the JSON response of a website to the database. Latter I am accessing this JSON string for processing the data. But I am not able to parse it as JSON object. On analyzing I realize that the characters of strings needs to be escaped. Since I am saving the data as a string the data results which am getting back as a JSON data are not escaped in the database. Is there a way out how I can save the JSON data to the database.</p> <p>Example:</p> <pre><code> {"RULE":[{"replace":{"value":"","type":"text"},"match":{"value":"&lt;a [^&gt;]*&gt;&lt;img src="[^"]*WindowsLiveWriter/IconsfordifferentSocialBookmarkingSites[^&gt;]*&gt;\s*&lt;/a&gt;","type":"text"}},{"replace":{"value":"","type":"text"},"match":{"value":"&lt;a [^&gt;]*&gt;&lt;img src="[^"]*WindowsLiveWriter/IconsfordifferentSocialBookmarkingSites[^&gt;]*&gt;\s*&lt;/a&gt;","type":"text"}}]} </code></pre> <p>Want to save in database as (also getting the response as) i.e. the " and \ are escaped</p> <pre><code> {"RULE":[{"replace":{"value":"","type":"text"},"match":{"value":"&lt;a [^&gt;]*&gt;&lt;img src=\"[^\"]*WindowsLiveWriter/IconsfordifferentSocialBookmarkingSites[^&gt;]*&gt;\\s*&lt;/a&gt;","type":"text"}},{"replace":{"value":"","type":"text"},"match":{"value":"&lt;a [^&gt;]*&gt;&lt;img src=\"[^\"]*WindowsLiveWriter/IconsfordifferentSocialBookmarkingSites[^&gt;]*&gt;\\s*&lt;/a&gt;","type":"text"}}]} </code></pre> <p>Here is the code I have used to save the data in the database</p> <pre><code> // here the raw_data is the data from the website JSONObject jo = new JSONObject(raw_data); // Get the JSONObject value associated with the search result key. jo = jo.getJSONObject("pipe"); jo = jo.getJSONObject("definition"); String def=jo.toString(); JSONArray jo1=jo.getJSONArray("modules"); JSONArray jo2=jo.getJSONArray("wires"); /* * Write the contents in the data base * * */ def =def.replaceAll( "[']", "\\\\\'" ); //creates problem for strings with ' def =def.replaceAll( "&amp;", "%26" ); String tablename="PipesTable2"; System.out.println(def); database d=new database(); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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