I'm trying to parse a json string embedded in my html file. Here is the reduced code.
<html>
<head>
<script src="./jquery-1.4.4.min.js" type="text/javascript"></script>
<script>
function parse_json(){
var jtext = $("#mtxt").text();
var jdata = jQuery.parseJSON(jtext);
JSON.parse(JSON.stringify(jdata), function (key, value){
alert("key=" + key + " value=" + value);
if(key== ""){
alert("value in string" + JSON.stringify(value));
}
});
}
$(document).ready(function() {
$("#run").click( function () {
parse_json();
});
});
</script>
</head>
<body>
<a id="run" href="#">run</a>
<div id="mtxt">
{"caller": "539293493"}
</div>
</body>
</html>
When I parse it, apart from the expected "caller" value, I get an extra empty "key" and "value". The first alert gives me
key= value=[object Object]
The second alert gives me
value in string{}
What is happening? Why this extra entry?