Javascript 我的json值正在开箱。如何漂亮地打印这些值?
您好,我是Angular JS新手,希望以正确的漂亮打印格式打印JSON数据,当我打印硬编码数据时,我的输出将以漂亮打印格式显示。但实际代码中,我的数据来自ccloud,而我并没有得到适当的小打印格式Javascript 我的json值正在开箱。如何漂亮地打印这些值?,javascript,jquery,json,angularjs,pretty-print,Javascript,Jquery,Json,Angularjs,Pretty Print,您好,我是Angular JS新手,希望以正确的漂亮打印格式打印JSON数据,当我打印硬编码数据时,我的输出将以漂亮打印格式显示。但实际代码中,我的数据来自ccloud,而我并没有得到适当的小打印格式 <script type="text/javascript"> $(document).ready( function() { alert("entered"); var json = do
<script type="text/javascript">
$(document).ready(
function() {
alert("entered");
var json = document.getElementById("jsonStr").value;
alert(json);
alert(document.getElementById("jsonStr1").value);
var jsonParse = JSON.parse(json);
var jsonFormatted = JSON.stringify(jsonParse, null, ' ');
document.getElementById("jsonDiv").innerHTML = '<pre>'
+ jsonFormatted + '</pre>';
});
</script>
<tab>
<tab-heading> Image Ancestry </tab-heading>
<div class="list-group">
<a ng-repeat="img in imageAncestry" class="list-group-item"
ng-class="{active: imageDetails.id==img}"> <span class="glyphicon"
ng-class="{'glyphicon-arrow-down': ($first&&!$last)||$middle}"></span>
<!-- {{img | limitTo:12}} --> <input id="jsonstr" type="text"
value={img} />
<div id="jsonDiv"></div>
</div>
</tab>
$(文件)。准备好了吗(
函数(){
警报(“输入”);
var json=document.getElementById(“jsonStr”).value;
警报(json);
警报(document.getElementById(“jsonStr1”).value);
var jsonParse=JSON.parse(JSON);
var jsonFormatted=JSON.stringify(jsonParse,null,”);
document.getElementById(“jsonDiv”).innerHTML=''
+jsonFormatted+“”;
});
影像祖先
有了{img | limito:12},json就开箱了。您可以使用以下方法:
JS:
$scope.json=angular.toJson(,true);
HTML:
{{json}}
如果您能在上创建一个演示,您能提供来自ccloud的数据示例吗?
$scope.json = angular.toJson(<YOUR-JSON>, true);
<!-- this is going to be indent and pretty print -->
{{json}}