我输入了json文件@ JSON,当我尝试用下面的代码解析它时:
<script>
//When DOM loaded we attach click event to button
$(document).ready(function() {
//after button is clicked we download the data
$('.button').click(function(){
//start ajax request
$.ajax({
url: "input_json.json",
//force to handle it as text
dataType: "text",
success: function(data) {
//data downloaded so we call parseJSON function
//and pass downloaded data
var json = $.parseJSON(data);
//now json variable contains data in json format
//let's display a few items
$('#results').html('Paper name: ' + json.Papername + '<br />Maximum Time: ' + json.MaxTime);
}
});
});
});
</script>
和HTML as:
<input type="button" value="Get and parse JSON" class="button" />
当我点击此按钮时,我在Firefox控制台中收到错误
SyntaxError: JSON.parse: unexpected character at line 2 column 1 of the JSON data
请帮忙解决这个问题。