(请原谅我在术语上的任何错误,我对json不是很熟悉)
我有一组地图,每个单元格都包含地图详细信息 [map] [details] 。当我将数组编码为json时,我得到了数组的有效json表示。
我的问题是如何将每个地图的1D数组更改为具有单元格描述的2D数组,例如" map_id" =" 23"而不只是" 23"?
self.net.blobs['data'].data[0] = img
self.net.forward(end=layer_list[-1])
feat_all = []
for layer in layer_list:
feat = np.zeros_like(self.net.blobs[layer].data[0])
feat[:] = self.net.blobs[layer].data[0]
feat_all.append(feat)
我只需使用
进行编码即可获得json$maps = UserMaps::getMapIDs($user_id); // get map IDs user has access to
$mapsData = array(); // create new array to store data
foreach ($maps as $key => $value) { // for maps user has access to
$mapsData[] = Maps::getMap($maps[$key]['map_id']); // push map data into new array
}
var_dump($mapsData);
if($mapsData == NULL) { echo "no maps to display"; }
return $mapsData; // return array with map data
我应该将数组转换为3D数组[maps] [detail] [value]然后编码吗?
答案 0 :(得分:0)
我通过在编码之前将2D阵列转换为3D阵列来修复它。以下是代码:
$maps = UserMaps::getMapIDs($user_id); // get map IDs user has access to
$mapsData = array(); // create new array to store data from the maps
foreach ($maps as $key => $value) { // for each map user has access to
$mapData = Maps::getMap($maps[$key]['map_id']); // get map properties
$map = array();
for($i=0; $i<11; $i++){
$property = array(); // create property array
$property[] = $properties[$i]; // add property title
$property[] = $mapData[$i]; // add value
$map[] = $property;
}
$mapsData[] = $map; // push map data into new array cell
}
// var_dump($mapsData);
if($mapsData == NULL) { echo "no maps to display"; }
return $mapsData;