Php 在安卓系统中进行改型时,json格式存在问题
我在从php文件获取JSON值时遇到了一个问题 我怎样才能修好它Php 在安卓系统中进行改型时,json格式存在问题,php,android,json,Php,Android,Json,我在从php文件获取JSON值时遇到了一个问题 我怎样才能修好它 <?php //If the values are not blank //Connecting to our database by calling dbConnect script include('connection.php'); $id =$_POST["uyeId"]; Class UyeBilgiler{ public $uyeAd = "";
<?php
//If the values are not blank
//Connecting to our database by calling dbConnect script
include('connection.php');
$id =$_POST["uyeId"];
Class UyeBilgiler{
public $uyeAd = "";
public $uyeYas = "";
public $uyeOkul = "";
public $uyeResim = "";
public $uyeEmail = "";
}
$uyeBilgiler = new UyeBilgiler();
$informationSql = "SELECT * FROM bilgiler WHERE id = '$id' ";
$list = mysqli_query($conn,$informationSql);
while($result = mysqli_fetch_assoc($list)){
$uyeBilgiler->uyeAd = $result["uyeAd"];
$uyeBilgiler->uyeYas = $result["uyeYas"];
$uyeBilgiler->uyeOkul = $result["uyeOkul"];
$uyeBilgiler->uyeResim = $result["uyeResim"];
$uyeBilgiler->uyeEmail = $result["uyeEmail"];
echo json_encode($uyeBilgiler,JSON_UNESCAPED_UNICODE|JSON_PRETTY_PRINT);
}
?>
第一个花式大括号之后和最后一个花式大括号之前有一个间隙
对于android部分
@GET("/getInformationByUyeId.php")
Call<UyeBilgiler> bilgiGetir(@Query("uyeId") String id);
@GET(“/getInformationByUyeId.php”)
调用bilgiGetir(@Query(“uyeId”)字符串id);
当我在不使用$_POST[“uyeId”]的情况下手动定义$id($id=“1”)时,我得到的json文件没有任何错误。但是使用$_POST[“uyeId”]会抛出一个错误,如下所示
应为BEGIN_对象,但在第1行第1列路径处为字符串$根据API响应创建一个模型类,如下所示
@SerializedName("uyeAd")
@Expose
private String uyeAd;
@SerializedName("uyeYas")
@Expose
private String uyeYas;
@SerializedName("uyeOkul")
@Expose
private String uyeOkul;
@SerializedName("uyeResim")
@Expose
private String uyeResim;
@SerializedName("uyeEmail")
@Expose
private String uyeEmail;
并将您的响应分配给模型类,如下所示
if(response.isSuccessful())
{
modelClass = response.body();
}
在modelClass中创建getter setter-mother并从中获取值,并显示在文本中
view txt.setText(“Isminize:+modelClass.getName())代码>显示UyeBilgiler
和服务器的Json响应,基本上是解析问题,类似于1的任何变量,您期望对象类型,但从响应中获取字符串,反之亦然versa@SaranSankaran我放置了UyeBilgiler类和来自JSON响应的错误。如您所见,@Ashish My JSON格式的可能重复以大括号开头。我编辑了文章。我认为这个问题来自于$_POST[“uyeId”]。嘿,兄弟,使用$_GET[“uyeId”];因为您在getMethod()中从android发送数据,在$_POST[]中接收数据;所以只要把它改成$_GET[];
if(response.isSuccessful())
{
modelClass = response.body();
}