-1
以下のJSON形式でデータをエンコードしようとしています。カテゴリ内にカテゴリ配列を追加することはできません。誰かが私にこれを助けることができますか?既存の配列にarraylistを追加する
{
"chart": {
"caption": "Product-wise Quarterly Revenue vs. Profit %",
"subCaption": "Harry's SuperMart - Last Year",
"xAxisname": "Quarter",
"pYAxisName": "Sales",
"sYAxisName": "Profit %",
"numberPrefix": "$",
"sNumberSuffix": "%",
"sYAxisMaxValue": "25",
"paletteColors": "#0075c2,#1aaf5d,#f2c500",
"bgColor": "#ffffff",
"borderAlpha": "20",
"showCanvasBorder": "0",
"usePlotGradientColor": "0",
"plotBorderAlpha": "10",
"legendBorderAlpha": "0",
"legendShadow": "0",
"legendBgAlpha": "0",
"valueFontColor": "#ffffff",
"showXAxisLine": "1",
"xAxisLineColor": "#999999",
"divlineColor": "#999999",
"divLineIsDashed": "1",
"showAlternateHGridColor": "0",
"subcaptionFontBold": "0",
"subcaptionFontSize": "14",
"showHoverEffect": "1"
},
"categories": [
{
"category": [
{
"label": "Q1"
},
{
"label": "Q2"
},
{
"label": "Q3"
},
{
"label": "Q4"
}
]
}
]
}
私のPHPコード:
$arrData = array(
"chart" => array(
"caption"=> "Product-wise Quarterly Revenue vs. Profit %",
"subCaption"=> "Harry's SuperMart - Last Year",
"xAxisname"=> "Quarter",
"pYAxisName"=> "Sales",
"sYAxisName"=> "Profit %",
"numberPrefix"=> "$",
"sNumberSuffix"=> "%",
"sYAxisMaxValue"=> "25",
"paletteColors"=> "#0075c2,#1aaf5d,#f2c500",
"bgColor"=> "#ffffff",
"borderAlpha"=> "20",
"showCanvasBorder"=> "0",
"usePlotGradientColor"=> "0",
"plotBorderAlpha"=> "10",
"legendBorderAlpha"=> "0",
"legendShadow"=> "0",
"legendBgAlpha"=> "0",
"valueFontColor"=> "#ffffff",
"showXAxisLine"=> "1",
"xAxisLineColor"=> "#999999",
"divlineColor"=> "#999999",
"divLineIsDashed"=> "1",
"showAlternateHGridColor"=> "0",
"subcaptionFontBold"=> "0",
"subcaptionFontSize"=> "14",
"showHoverEffect"=> "1"
)
);
$arrData["categories"] = array();
$arrData["category"] = array();
//array_push($arrData["categories"],array($arrData["category"]));
//array_push($arrData["categories"],array($arrData["category"]));
array_push($arrData["category"], array(
"label" => "Q1",
));
array_push($arrData["category"], array(
"label" => "Q2",
));
$json_string = json_encode($arrData, JSON_PRETTY_PRINT);
echo $json_string;
}
PHP出力:
が出力希望ちなみに
{
"chart": {
"caption": "Product-wise Quarterly Revenue vs. Profit %",
"subCaption": "Harry's SuperMart - Last Year",
"xAxisname": "Quarter",
"pYAxisName": "Sales",
"sYAxisName": "Profit %",
"numberPrefix": "$",
"sNumberSuffix": "%",
"sYAxisMaxValue": "25",
"paletteColors": "#0075c2,#1aaf5d,#f2c500",
"bgColor": "#ffffff",
"borderAlpha": "20",
"showCanvasBorder": "0",
"usePlotGradientColor": "0",
"plotBorderAlpha": "10",
"legendBorderAlpha": "0",
"legendShadow": "0",
"legendBgAlpha": "0",
"valueFontColor": "#ffffff",
"showXAxisLine": "1",
"xAxisLineColor": "#999999",
"divlineColor": "#999999",
"divLineIsDashed": "1",
"showAlternateHGridColor": "0",
"subcaptionFontBold": "0",
"subcaptionFontSize": "14",
"showHoverEffect": "1"
},
"categories": [
],
"category": [
{
"label": "Q1"
},
{
"label": "Q2"
}
]
}
ありがとう。私はこれを試してみる – ram