为了账号安全,请及时绑定邮箱和手机立即绑定

Android应用程序解码来自PHP MySql数据库的JSON响应,没有特殊字符

Android应用程序解码来自PHP MySql数据库的JSON响应,没有特殊字符

PHP
江户川乱折腾 2022-07-22 15:20:13
我正在尝试从 mydatabase中检索一些数据android app,但某些特殊字符发送不正确。数据实际上首先从我的应用程序发送,存储,然后检索。当我发送它时,数据以正确的方式注册,但在检索时似乎存在编码/解码问题。为了正确存储数据,我使用mysqli_set_charset($conn, 'utf8');了命令,因此数据Situație 4在发送时存储。发送数据的 PHP 代码:$stmt->bind_result($id, $latitudine, $longitudine, $tip_problema, $data_ora, $ora_catalogare, $validare, $grad_incredere);                while($stmt->fetch()) {                    $locatie[] = array (                            "id_alerta"=>$id,                            "latitudine"=>$latitudine,                             "longitudine"=>$longitudine,                             "tip_problema"=>$tip_problema,                            "data_ora"=>$data_ora,                            "ora_catalogare"=>$ora_catalogare,                            "stare_problema"=>$validare,                            "grad_incredere"=>$grad_incredere                            );            $response['error'] = false;             $response['message'] = 'Alerte reimprospatate';            $response['locatie']= $locatie;                } 我需要的信息存储在 $locatie 中,所以我可以在我的应用程序上获得 JSON 响应。输入 JSON 响应的应用代码:@Override        protected void onPostExecute(String s) {            super.onPostExecute(s);            //hiding the progressbar after completion            try {                //converting response to json object                JSONObject obj = new JSONObject(s);                //if no error in response                if (!obj.getBoolean("error")) {                    Toast.makeText(getApplicationContext(), obj.getString("message"), Toast.LENGTH_SHORT).show();
查看完整描述

1 回答

?
holdtom

TA贡献1805条经验 获得超10个赞

请尝试给 BufferedReader 编码

 BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream(),"UTF-8"));



查看完整回答
反对 回复 2022-07-22
  • 1 回答
  • 0 关注
  • 141 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号