我如何访问具有空格的对象属性[重复](how can i access the object properties that have spaces [duplicate])
在下面的json文件中我想访问“个人详细信息”,但我怎么能这样做,它与其他对象键不同。
{ "data": { "personal details": { "name": "Loren", "father's name'": "Geroge", "mother's name": "Lita" }, "class": { "name": "Loren Gothem", "class": 7, "division": "3rd" }, "address": { "temporary address": "Acn Block Ist Phase", "permanent address": "Bozane Trail Building Ist Floor" } } }
This question already has an answer here:
in the below json file i want to access the "personal details", but how can i do that, it different from other object keys.
{ "data": { "personal details": { "name": "Loren", "father's name'": "Geroge", "mother's name": "Lita" }, "class": { "name": "Loren Gothem", "class": 7, "division": "3rd" }, "address": { "temporary address": "Acn Block Ist Phase", "permanent address": "Bozane Trail Building Ist Floor" } } }
原文:https://stackoverflow.com/questions/41593306
更新时间:2024-01-25 13:01
最满意答案
工作实例。
<?php $completed = 50; $new = 10; $total = 30; ?> <html> <head> <!--Load the AJAX API--> <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script> <script type="text/javascript"> google.charts.load('current', {'packages':['corechart']}); google.charts.setOnLoadCallback(drawChart); function drawChart() { var data = google.visualization.arrayToDataTable([ ['Order', 'Amount'], ['Completed', parseInt('<?php echo $completed; ?>')], ['New', parseInt('<?php echo $new; ?>')] ]); var options = { title: 'Total Order ' + <?php echo$total; ?> }; var chart = new google.visualization.PieChart(document.getElementById('piechart')); chart.draw(data, options); } </script> </head> <body> <div id="piechart"></div> </body> </html>
Working Example.
<?php $completed = 50; $new = 10; $total = 30; ?> <html> <head> <!--Load the AJAX API--> <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script> <script type="text/javascript"> google.charts.load('current', {'packages':['corechart']}); google.charts.setOnLoadCallback(drawChart); function drawChart() { var data = google.visualization.arrayToDataTable([ ['Order', 'Amount'], ['Completed', parseInt('<?php echo $completed; ?>')], ['New', parseInt('<?php echo $new; ?>')] ]); var options = { title: 'Total Order ' + <?php echo$total; ?> }; var chart = new google.visualization.PieChart(document.getElementById('piechart')); chart.draw(data, options); } </script> </head> <body> <div id="piechart"></div> </body> </html>
相关问答
更多-
它真的很简单。 我需要做的就是从JSON格式的数据库获取数据并传入 var data = new google.visualization.DataTable($sales_data); 功能而不是 var data = google.visualization.arrayToDataTable([$sales_data]) 它有效。 谢谢大家的支持和时间........... it Was really simple. all i need to do was get data from DB in ...
-
如果你可以提供总是数字 - 删除引号。 使用: var countni3=; 或者如果您不确定: var countni3=parseInt("") || 0; 例: var countra1=parseInt("") || 0; var countrf2 ...
-
使用CodeIgniter基于JSON数据创建Google饼图(Creating Google Pie Chart based on JSON data using CodeIgniter)[2023-12-08]
代替: var popularCategory = google.visualization.DataTable(jsonData); 你必须有: var popularCategory = new google.visualization.DataTable(jsonData); instead of: var popularCategory = google.visualization.DataTable(jsonData); you must have: var popularCategory ... -
尝试这个: $scope.chartpie.options = { "slices": {}, "title": "Title is here", "isStacked": "true", "sliceVisibilityThreshold": 0, "displayExactValues": true }; ...
-
试试这个sql ... $query = "SELECT sub_cat, SUM(sub_amount) as subs_total FROM subscriptions WHERE sub_user_id ='".$user_id."' GROUP BY sub_cat ORDER BY sub_cat"; 该类别应该是第一列和小计秒。 try this sql... $query = "SELECT sub_cat, SUM(sub_amount) as subs_total FROM subscri ...
-
知道了,我怀疑它有点愚蠢: 我分配给js变量的PHP变量是字符串...... Got it, it was something sort of silly as I suspected: the PHP variables I assigned to the js variables were strings...
-
我认为代码中的错误是打开/关闭