douyuefei3546 2018-09-05 13:43
浏览 65

在android中为对象数组创建json模型和api

I want to create JSON model and API for array of JSON object. my PHP code:

<?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 {
  }
    ?>

and my JSON model:

   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;
    }
    }
   }

and my API:

     @FormUrlEncoded
     @POST("project/searchBidProject.php")
     Call<List<browsprojectJm>> browsproject(@Field("type") int  
      type_register);

output with postman:

{
"products": [
    {
        "projectId": "1",
        "title": "خرید خانه",
        "createTime": "2018-09-05"
    },
    {
        "projectId": "3",
        "title": "خرید خانه شخصی",
        "createTime": "2018-09-05"
    },
    {
        "projectId": "4",
        "title": "خرید من",
        "createTime": "2018-09-05"
    }
]
 }

but this not working and i don't know what's wrong. it fails without errors but I think this problem is from JSON model or api.I'm new in android developing and please explain for me clearly

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥30 win from 窗口最大最小化,控件放大缩小,闪烁问题
    • ¥20 易康econgnition精度验证
    • ¥15 msix packaging tool打包问题
    • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
    • ¥15 python的qt5界面
    • ¥15 无线电能传输系统MATLAB仿真问题
    • ¥50 如何用脚本实现输入法的热键设置
    • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
    • ¥30 深度学习,前后端连接
    • ¥15 孟德尔随机化结果不一致