I am working on a web application based on struts+java+hibernate framework. The underlying database is MySQL 5.
The user activities are recorded in the DB and later on shown to other users. When a user does some activity, the information pertaining to the activity is also stored along with the activity. There is now an implementation change. Earlier this activity information was stored as plain text but now it is stored as json for ease of usage(considering the fact that this information can have many values as null).
The information stored is later on used for displaying the activity on the web page.
For all the new activities, (information)data gets JSON encoded in the java code and encoded JSON string is stored in DB. The problem is with data corresponding to the old activities.
Is there any way to JSON encode the data stored in DB?. Or Is there any way in jquery/javascript to encode the string in JSON format and then get the Json object constructed back properly?
The general format of the data to be stored in DB(after migration) is:
{"key1":"value1", "key2":"value2","key3":"value3",...}
and data already in DB is in format:
value1,value2,value3,...
These values (namely value1,value2, value3,...) can contain any special characters.
JSONis an acronym forJavaScript Object Notation, so your asking if there is a JS way to encode/decode a JavaScript Object from and to a string? The answer is yes:JSON.parse,JSON.stringify. The format in your DB looks pretty JSON-y to me already...JSON.stringifywill escape quotes, if it didn't they'd be string delimiters. The escaping `` isn't being escaped, so it's not part of the string itself, it merely escapes the quote. Unless you're stringifying the the object twice. Special chars shouldn't be an issue, if they're part of the string, they're just a char constant, nothing more, nothing less