php json encode
This below output come from php json_encode.What we see here is 0849 is twice.Since javascript only use sn to get value why we need the "0" value.The main problem is speed execution. If 800 kb data might can be reduce to 400 kb 开发者_如何学Python
{"success":"true","total":968,"data":[{"0":"0849","sn":"0849" }]
If no solution i have to make a script to filter in json_encode so no need twice data transter.
The 0 entry is because your array contains a 0 entry! I'm going to guess that you're retrieving it from a database, using something like mysql_fetch_array
; in this case, you can simply change to using mysql_fetch_assoc
(which returns a straight forward associative array), or by passing MYSQL_ASSOC
as the second argument to mysql_fetch_array
. If you're using other DB sources, similar functions exist.
If it's not coming from a database (or you need the numeric keys elsewhere) you can always filter the numerical values out. You can do this by stringing a bunch of array_* functions together, or just with a foreach loop:
foreach ($data as $k => $v) { if (is_int($k)) { unset($data[$k]); } }
精彩评论