我想第一次使用json編碼,需要一些洞察力,我做錯了什麼。使用json編碼
它應該是這樣的:
{隊:[[ 「2147483647」, 「9」],[ 「2147483647」, 「6」],[ 「2147483647」, 「4」], [「11」,「2147483647」],[「5」,「2147483647」],[「12」,「8」],[「10」,「3」],[「2147483647」,「7」 ] [0,1],[0,1],[1,0],[1,0],[0,0],[0,0],[ 0,1],[0,0],[0,0],[0,0],[0,0],],[[0,0],[0,0],],[ [0,0],[0,0]]]]}
但返回的數據看起來像這樣: -
{「teams」:[[「2147483647」,「10」,「5」,「12」,「11」,「2147483647」,「2147483647」,「2147483647」],[「7」,「3」 , 「2147483647」, 「8」, 「2147483647」, 「4」, 「6」, 「9」]], 「結果」:[[ 「0」, 「0」, 「0」, 「0」,」 0" , 「0」, 「0」, 「0」],[ 「0」, 「0」, 「0」, 「0」, 「0」, 「0」, 「0」, 「0」]] }
代碼:
public function getAutoCompleteData($tournID, $db)
{
$max = $this->max($tournID);
$one = $this->tourn_info("1on1", $tournID);
$total_matches = $max;
$after_matches = $max/2;
$matches = $db->query($this->select("*", "matches", "leagueID='{$tournID}' AND league='tourn'"));
while ($row = $db->fetchAssoc($matches)) {
$clan1 = $this->getname($row['clan1'], $tournID, "tourn", $ac = NULL, 1, 1, $wc2 = 0);
$clan2 = $this->getname($row['clan2'], $tournID, "tourn", $ac = NULL, 1, 1, $wc2 = 1);
if ($row['matchno'] <= $after_matches) {
$clan_one[] = $row['clan1'];
$clan_two[] = $row['clan2'];
$score_one[] = $row['score1'];
$score_two[] = $row['score2'];
}
}
$data = array(
'teams' => array(
$clan_one,
$clan_two
),
'results' => array(
$score_one,
$score_two
)
);
return $data;
}
顯示位置的球隊,就應該關閉支架]
每兩支球隊? 希望有人能幫助。
但第一個代碼不是JSON ... – elclanrs
你的班級在哪裏? '$ this'是指一個類。在類中使構造函數使用'public function __construct(){}'。 – PHPglue
你的代碼很混亂。變量$ 1,$ clan1,$ clan2永遠不會被使用。您正在創建一個包含兩個項目的數組,每個項目都有兩個項目。你的JSON顯示的是什麼。 – Mundi