Within my JavaScript code, a variable holds the following information:
url=http://localhost
quality=100
tag="4.4, 5.5"
I am interested in converting this data to JSON format using JavaScript, like this:
"result": {
"url": "http://localhost",
"quality": "100",
"tag": "4.4, 5.5",
}
What is the best way to accomplish this conversion to JSON?
HTML
<textarea cols="100" rows="10" id="textarea_one"></textarea>
<textarea cols="100" rows="10" id="textarea_two"></textarea>
JS
var objLoadHTML = document.getElementById('textarea_one');
var strContent = objLoadHTML.value;
var Reg = /(?:(\w+)=([^\n\r]+))*/gm;
var match = Reg.exec(strContent);
while (match != null) {
document.getElementById('textarea_two').innerHTML += match;
match = Reg.exec(strContent);
}
document.getElementById('textarea_two').innerHTML = match;