Umidjon Urunov
Umidjon Urunov

Reputation: 671

Creation of new JSON Object

I am using Google Graphs and I am getting data from MySQL database and encoding it with PHP to JSON and sending it from controller to view. But the problem is date is sending as string and graph cannot use this date. And I changed date to unix system and sending it to view I can get date as a date.

[[1383424123,"AAA",0.001735],[1383424518,"AAA",0.001689],[1383424123,"BBB",0.65211],[1383424518,"BBB",0.655739],[1383424123,"CCC",1],[1383424518,"CCC",1]]

Above I am getting this json object from controller.

In view I am using this json object for Google Graph :

<script> var jsonData=<?php echo $jsdata;?> </script>

I need to get date unix system values and create new date like ->

new Date(jsonData[i][0] * 1000); 

And create new the same json object but with new date ( will be replaced with new Date(jsonData[i][0] * 1000); values ) which I am getting from controller and rest of data should remain. How can I do it, creating new json object with replaced date values (only date).

Upvotes: 0

Views: 85

Answers (1)

Felix Kling
Felix Kling

Reputation: 816472

You can just modify the existing value of the array by assigning back to it:

jsonData[i][0] = new Date(jsonData[i][0] * 1000);.

Upvotes: 2

Related Questions