-1

How to encode below json with php

'{ "chart": { "caption": "Actual Revenues, Targeted Revenues & Profits", "subcaption": "Last year", "xaxisname": "Month", "yaxisname": "Amount (In USD)", "numberprefix": "$", "theme": "zune" },

  "categories": [ { "category": [ { "label": "Jan" }, { "label": "Feb" }, { "label": "Mar" }, { "label": "Apr" }, { "label": "May" }, { "label": "Jun" }, { "label": "Jul" }, { "label": "Aug" }, { "label": "Sep" }, { "label": "Oct" }, { "label": "Nov" }, { "label": "Dec" } ] } ], 

"dataset": [ { "seriesname": "Actual Revenue", "data": [ { "value": "16000" }, { "value": "20000" }, { "value": "18000" }, { "value": "19000" }, { "value": "15000" }, { "value": "21000" }, { "value": "16000" }, { "value": "20000" }, { "value": "17000" }, { "value": "25000" }, { "value": "19000" }, { "value": "23000" } ] }, 
  { "seriesname": "Projected Revenue", "renderas": "line", "showvalues": "0", "data": [ { "value": "15000" }, { "value": "16000" }, { "value": "17000" }, { "value": "18000" }, { "value": "19000" }, { "value": "19000" }, { "value": "19000" }, { "value": "19000" }, { "value": "20000" }, { "value": "21000" }, { "value": "22000" }, { "value": "23000" } ] }, 
  { "seriesname": "Profit", "renderas": "area", "showvalues": "0", "data": [ { "value": "4000" }, { "value": "5000" }, { "value": "3000" }, { "value": "4000" }, { "value": "1000" }, { "value": "7000" }, { "value": "1000" }, { "value": "4000" }, { "value": "1000" }, { "value": "8000" }, { "value": "2000" }, { "value": "7000" } ] } ] }');
JON
  • 965
  • 2
  • 10
  • 28
  • Possible duplicate of [JSON encode MySQL results](https://stackoverflow.com/questions/383631/json-encode-mysql-results) – GeralexGR Sep 30 '17 at 07:16

4 Answers4

0

Use json_decode($your_json_string_here) to create a PHP object from your JSON.

Cobolt
  • 935
  • 2
  • 11
  • 24
0

Please refer Official php documentation http://php.net/manual/en/function.json-decode.php

Raj Swami
  • 65
  • 1
  • 9
0

its vary simple use var_dump(json_decode($json, true));

DEMO

JON
  • 965
  • 2
  • 10
  • 28
0
<?php
$myObj->name = "John";
$myObj->age = 30;
$myObj->city = "New York";

$myJSON = json_encode($myObj);

echo $myJSON;
?>

output
{"name":"John","age":30,"city":"New York"}

<?php
$json = '{"a":1,"b":2,"c":3,"d":4,"e":5}';

var_dump(json_decode($json));
var_dump(json_decode($json, true));

?>

output
object(stdClass)#1 (5) {
    ["a"] => int(1)
    ["b"] => int(2)
    ["c"] => int(3)
    ["d"] => int(4)
    ["e"] => int(5)
}

array(5) {
    ["a"] => int(1)
    ["b"] => int(2)
    ["c"] => int(3)
    ["d"] => int(4)
    ["e"] => int(5)
}