php json_encode and decode multi-dimension array -


i have php array structure

array (     [car] => array         (             [red] => 0.333             [orange] => 0.333             [blue] => 0.333         )      [truck] => array         (             [white] => 0.333             [green] => 0.333             [blue] => 0.333         ) ) 

i have been using serialize save array text file, , unserialize array form. unfortunately, serialized array getting large, due float point (bug or design) conversion when serialized. example, instead of 0.333, serialized process converts .333 .3333333333333333333333333333333333333333333333333. made me want switch json_encode save array. when compare serialize json_encode, serialized file 40mb in size vs 8mb size json_encode.

that great, except when try json_decode file, no longer in array form. tried json_decode($array, true), not work either.

any idea how json_encode work example?

tia

ps, floating point number generated rounding off decimals. answer found on stacko suggested instead of using round($part/$sum, 3);, use sprintf('%.3f', $part/$sum); turned floating point string. alone cut serialized file down 40mb 19mb, still larger json_encode file size of 8mb.

the 'problem' due json_decode inability read large json_encode files. largest json file can work ~.5mb. tested on 4gb ram, 4 core xeon server, , 4gb localhost laptop. had set memory_limit in php.ini file 3gb other php routines (yes, 3gb) , restarted apache. memory_limit setting appears not problem.

error message not helpful, stated

warning: array_slice() expects parameter 1 array, null given in /home/xxxxx/public_html/xxxx.php on line xx

hopefully error message person in future narrow down bug.


Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -