How to convert content of web page to json file ? Like I pass the url of page n it got converted to json file. Web page only contains json string.
Asked
Active
Viewed 3,497 times
-1
-
What language are you looking to do this in? – jtmarmon Jan 05 '15 at 05:54
-
I want to write java code for this conversion – Bhoomi Akhani Jan 05 '15 at 05:56
-
See http://stackoverflow.com/questions/4308554/simplest-way-to-read-json-from-a-url-in-java for the answer in java – jtmarmon Jan 05 '15 at 05:57
-
Do you want to show json string only in the page? – Mehmet Otkun Jan 05 '15 at 06:02
-
I have one url and it contains only json formatted data. I want to create a method to convert that url to .json file – Bhoomi Akhani Jan 05 '15 at 06:31
1 Answers
0
Also you can do it with ajax
<script type="text/javascript">
function loadJSONDoc(url) {
var xmlhttp;
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
} else {
// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 ) {
if(xmlhttp.status == 200){
document.getElementById("myBody").innerHTML = xmlhttp.responseText;
//if your response text is JSON object
document.getElementById("myBody").innerHTML = JSON.stringify(xmlhttp.responseText);
}
else if(xmlhttp.status == 400) {
alert('There was an error 400')
}
else {
alert('something else other than 200 was returned')
}
}
}
xmlhttp.open("GET", url, true);
xmlhttp.send();
}
loadJSONDoc("your_url")
</script>

Community
- 1
- 1

Mehmet Otkun
- 1,374
- 9
- 22