我想使用这样的改造界面。
public interface ApiInterface {
@GET("test.php")
Call<Person> getPerson(@Query("name") String keyword);
}
我有这个错误,因为我已经像这样挤压并执行了 php 。
com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was BEGIN_ARRAY at line 1 column 2 path $
我想用Call<Person>,我不想用Call<List<Person>>
这是我制作的 php。
<?php
require_once 'conn.php';
if(isset($_GET['name'])) {
$name = $_GET['name'];
$query = "SELECT `NAME`, AGE, `ADDRESS` FROM test WHERE `NAME` = '$name'";
$result = mysqli_query($conn, $query);
$response = array();
while($row = mysqli_fetch_assoc($result)) {
array_push(
$response, array(
'name'=>$row['NAME'],
'age'=>$row['AGE'],
'address'=>$row['ADDRESS'])
);
}
echo json_encode($response);
}
mysqli_close($conn);
?>
这是 POJO 人。
public class Person {
@SerializedName("name") private String name;
@SerializedName("age") private int age;
@SerializedName("address") private String address;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
}
人到中年有点甜
慕妹3242003