Php JSON编码响应
我已经编写了一个php代码来将响应编码为JSON,但是除了所需的JSON编码之外,我还得到了一些其他东西。有人能告诉我代码出了什么问题吗?提前谢谢 下面是PHP代码集 db_config.php:-Php JSON编码响应,php,json,Php,Json,我已经编写了一个php代码来将响应编码为JSON,但是除了所需的JSON编码之外,我还得到了一些其他东西。有人能告诉我代码出了什么问题吗?提前谢谢 下面是PHP代码集 db_config.php:- <?php define('DB_USER', "root"); define('DB_PASSWORD', ""); define('DB_DATABASE', "androidhive"); define('DB_SERVER', "localhost"); ?> 所需的J
<?php
define('DB_USER', "root");
define('DB_PASSWORD', "");
define('DB_DATABASE', "androidhive");
define('DB_SERVER', "localhost");
?>
所需的JSON响应:-
{
"examination":[
{
"examid":"1",
"subid":"1",
"courseid":"1",
"internaltype":"1",
"maxmarks":"30",
"scored":"27",
"percentage":"90",
"result":"PASS-Distinction"
}
]
}
{
"examination":[
{
"examid":"1",
"subid":"1",
"courseid":"1",
"internaltype":"1",
"maxmarks":"30",
"scored":"27",
"percentage":"90",
"result":"PASS-Distinction"
},
{
"examid":"2",
"subid":"1",
"courseid":"1",
"internaltype":"1",
"maxmarks":"30",
"scored":"21",
"percentage":"70",
"result":"PASS-First Class"
}
]
}
{
"examination":[
{
"examid":"1",
"subid":"1",
"courseid":"1",
"internaltype":"1",
"maxmarks":"30",
"scored":"27",
"percentage":"90",
"result":"PASS-Distinction"
},
{
"examid":"2",
"subid":"1",
"courseid":"1",
"internaltype":"1",
"maxmarks":"30",
"scored":"21",
"percentage":"70",
"result":"PASS-First Class"
},
{
"examid":"3",
"subid":"1",
"courseid":"1",
"internaltype":"1",
"maxmarks":"30",
"scored":"24",
"percentage":"80",
"result":"PASS-First Class"
}
]
}
{
"examination":[
{
"examid":"1",
"subid":"1",
"courseid":"1",
"internaltype":"1",
"maxmarks":"30",
"scored":"27",
"percentage":"90",
"result":"PASS-Distinction"
},
{
"examid":"2",
"subid":"1",
"courseid":"1",
"internaltype":"1",
"maxmarks":"30",
"scored":"21",
"percentage":"70",
"result":"PASS-First Class"
},
{
"examid":"3",
"subid":"1",
"courseid":"1",
"internaltype":"1",
"maxmarks":"30",
"scored":"24",
"percentage":"80",
"result":"PASS-First Class"
}
],
"success":1
}
{
"examination":[
{
"examid":"1",
"subid":"1",
"courseid":"1",
"internaltype":"1",
"maxmarks":"30",
"scored":"27",
"percentage":"90",
"result":"PASS-Distinction"
},
{
"examid":"2",
"subid":"1",
"courseid":"1",
"internaltype":"1",
"maxmarks":"30",
"scored":"21",
"percentage":"70",
"result":"PASS-First Class"
},
{
"examid":"3",
"subid":"1",
"courseid":"1",
"internaltype":"1",
"maxmarks":"30",
"scored":"24",
"percentage":"80",
"result":"PASS-First Class"
}
],
"success":1
}
试一试
删除此
echo json_encode($response)代码>从内部,而循环。哦,该死…我没有看到那一个!!非常感谢你给我指出一个我可以吃奶酪汉堡的人
{
"examination":[
{
"examid":"1",
"subid":"1",
"courseid":"1",
"internaltype":"1",
"maxmarks":"30",
"scored":"27",
"percentage":"90",
"result":"PASS-Distinction"
}
]
}
{
"examination":[
{
"examid":"1",
"subid":"1",
"courseid":"1",
"internaltype":"1",
"maxmarks":"30",
"scored":"27",
"percentage":"90",
"result":"PASS-Distinction"
},
{
"examid":"2",
"subid":"1",
"courseid":"1",
"internaltype":"1",
"maxmarks":"30",
"scored":"21",
"percentage":"70",
"result":"PASS-First Class"
}
]
}
{
"examination":[
{
"examid":"1",
"subid":"1",
"courseid":"1",
"internaltype":"1",
"maxmarks":"30",
"scored":"27",
"percentage":"90",
"result":"PASS-Distinction"
},
{
"examid":"2",
"subid":"1",
"courseid":"1",
"internaltype":"1",
"maxmarks":"30",
"scored":"21",
"percentage":"70",
"result":"PASS-First Class"
},
{
"examid":"3",
"subid":"1",
"courseid":"1",
"internaltype":"1",
"maxmarks":"30",
"scored":"24",
"percentage":"80",
"result":"PASS-First Class"
}
]
}
{
"examination":[
{
"examid":"1",
"subid":"1",
"courseid":"1",
"internaltype":"1",
"maxmarks":"30",
"scored":"27",
"percentage":"90",
"result":"PASS-Distinction"
},
{
"examid":"2",
"subid":"1",
"courseid":"1",
"internaltype":"1",
"maxmarks":"30",
"scored":"21",
"percentage":"70",
"result":"PASS-First Class"
},
{
"examid":"3",
"subid":"1",
"courseid":"1",
"internaltype":"1",
"maxmarks":"30",
"scored":"24",
"percentage":"80",
"result":"PASS-First Class"
}
],
"success":1
}
{
"examination":[
{
"examid":"1",
"subid":"1",
"courseid":"1",
"internaltype":"1",
"maxmarks":"30",
"scored":"27",
"percentage":"90",
"result":"PASS-Distinction"
},
{
"examid":"2",
"subid":"1",
"courseid":"1",
"internaltype":"1",
"maxmarks":"30",
"scored":"21",
"percentage":"70",
"result":"PASS-First Class"
},
{
"examid":"3",
"subid":"1",
"courseid":"1",
"internaltype":"1",
"maxmarks":"30",
"scored":"24",
"percentage":"80",
"result":"PASS-First Class"
}
],
"success":1
}
$response["examinations"] = array();
$examination = array();
while($row = mysql_fetch_array($result))
{
$examination["examid"] = $row["examid"];
$examination["subid"] = $row["subid"];
$examination["courseid"] = $row["courseid"];
$examination["internaltype"] = $row["internaltype"];
$examination["maxmarks"] = $row["maxmarks"];
$examination["scored"] = $row["scored"];
$examination["percentage"] = $row["percentage"];
$examination["result"] = $row["result"];
array_push($response["examinations"], $examination);
}
echo json_encode($response);