我想为JSON对象数组创建JSON模型和API。 我的PHP代码:
<?php
$response = array();
require_once __DIR__ . '/db_connect.php';
$db = new DB_CONNECT();
if (isset($_POST['type'])) {
$type = $_POST['type'];
$result = mysql_query("SELECT *FROM bidsproject WHERE type='$type'
ORDER BY createTime ") ;
if (mysql_num_rows($result)>0) {
$response["products"] = array();
while ($row = mysql_fetch_array($result)) {
$product = array();
$product["projectId"] = $row["projectId"];
$product["title"] = $row["title"];
$product["createTime"] = $row["createTime"];
array_push($response["products"], $product);
}
echo json_encode($response);
}
else {
}
}
else {
}
?>
和我的JSON模型:
public class browsprojectJm {
int success;
public int getSuccess() {
return success;
}
public void setSuccess(int success) {
this.success = success;
}
DataToken project;
public class DataToken{
int projectId;
String title;
String creaeteTime;
public int getId() {
return projectId;
}
public void setId(int id) {
this.projectId = id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getDate() {
return creaeteTime;
}
public void setDate(String date) {
this.creaeteTime=date;
}
}
}
和我的API:
@FormUrlEncoded
@POST("project/searchBidProject.php")
Call<List<browsprojectJm>> browsproject(@Field("type") int
type_register);
邮递员输出:
{
"products": [
{
"projectId": "1",
"title": "خرید خانه",
"createTime": "2018-09-05"
},
{
"projectId": "3",
"title": "خرید خانه شخصی",
"createTime": "2018-09-05"
},
{
"projectId": "4",
"title": "خرید من",
"createTime": "2018-09-05"
}
]
}
但是这不起作用,我不知道怎么了。它失败了并且没有错误,但是我认为这个问题来自JSON模型或api。我是android开发的新手,请为我清楚地解释