We would like to know how to create SQL from JSON value.
<!--from ww w . ja v a 2 s.c o m-->
<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'
src='http://code.jquery.com/jquery-1.9.1.js'></script>
<script type='text/javascript'>
$(window).load(function(){
var table = {"table":[{"id":"1","name":"Joe","nick":"falk","year":"20"},
{"id":"2","name":"Mark","nick":"master","year":"50"},
{"id":"3","name":"John","nick":"jx","year":"20"},
{"id":"4","name":"Maria","nick":"beauty","year":"20"}]};
var aString = [];
$.each(table.table,function(index, item){
aString.push("INSERT INTO table VALUES('"+ item.id + "','"+ item.name + "','"+ item.nick + "','"+ item.year +"')");
$("#json").html(aString.join("<br />"));
});
});
</script>
</head>
<body>
<p id="json"></p>
</body>
</html>
The code above is rendered as follows: