gpt4 book ai didi

php - 特殊字符如 č,š,ž 从 php 到 android TextView

转载 作者:行者123 更新时间:2023-11-29 18:29:34 25 4
gpt4 key购买 nike

我刚刚遇到一个问题,当我从服务器读取 php 到 android 应用程序时,输出不是“šinko”,而是输出“Å¡inko”。但是当我调用“hhttp.website/data.php”(php 的名称)时,我得到正确的输出。但是当我从我的 Android 应用程序中读取它时,有些困惑...... 你知道我应该做什么吗?我的java代码;

public class Admin extends AppCompatActivity {

private TextView test;
String text;
List<String> list;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_admin);
test = (TextView) findViewById(R.id.test);
BackgroundWorker backgroundWorker = new BackgroundWorker(this);
String type = "data";

try {
text = backgroundWorker.execute(type).get();
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}
list = new ArrayList<>(Arrays.asList(text.split("/")));
for(String x : list){
System.out.println(x);
}

}

}

 <?php
require "conn.php";
$mysql_query = "SELECT
Name,
Surname,
Name_of_fee,
sum(Cost) as dept
FROM Person
JOIN Relation ON Person.ID = Relation.Person_ID
JOIN Fee ON Fee.ID = Relation.Fee_ID
GROUP BY Person.ID;";
$result = mysqli_query($conn, $mysql_query);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
echo "". $row["Name"]." " . $row["Surname"]. " " . $row["dept"]."<br>" ;
}
} else {
echo "0 results";
}
?>

最佳答案

您需要将 header 设置到 PHP 文件中

header('Content-type: text/plain; charset=utf-8');

然后需要将数据转换为base64编码

base64_encode($result)

当你在android中得到响应时,你首先需要转换你编码的字符串来解码你进入你的textview的特殊字符,Android解码

byte[] data = Base64.decode(base64, Base64.DEFAULT);
String text = new String(data, "UTF-8");

关于php - 特殊字符如 č,š,ž 从 php 到 android TextView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45826576/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com