嗨,我正在尝试 json_code 一个关联数组,其中最终结果应该看起来像下面的这个 json 数组
var json =[{ "adjacencies": [
{
"nodeTo": "graphnode9",
"nodeFrom": "graphnode5",
"data": {}
}
],
"data": {
"$color": "#C74243",
"$type": "triangle"
},
"id": "graphnode5",
"name": "graphnode5"
}];
这是我尝试将关联数组放入 json_encode 但它似乎不起作用,您可能会看到任何错误吗?太感谢了
function getjson(){
$db = adodbConnect();
$query = "SELECT nodes.*, relationships.* FROM nodes inner JOIN relationships ON nodes.id = relationships.id";
$result = $db -> Execute($query);
while($row=$result->FetchRow())
{
$id= (float)$row['id'];
$name = $row['name'];
$color1 = $row['color'];
$type1 = $row['type'];
$to= (float)$row['to'];
$array = array(
"adjacencies:" => array(
"nodeTo" => "$to",
"nodeFrom" => "$id",
"data" => array() ),
"data" => array(
"$"."color" => $color1,
"$"."type" => $type1 ),
"id".":" => $id,
"name".":" => $name);
}
print"$array";
json_encode($array);
}