首页 > 编程知识 正文

json返回中文乱码,序列化数组转前台json对象

时间:2023-05-05 16:02:35 阅读:128345 作者:1444

在我的安卓应用程序,I ' mtryingtocommunicatewithawebserverthatholdsrandomly-generatedfakeusernamesandscores。

{ scores: [

{

un: 'Feltricapulta ',

sc: '143 '

(,

{

un: 'Henroid ',

sc: '120 '

(,

{

un: 'ieteubmospta ',

sc: '70 '

(,

{

un: 'pmbotesteuai ',

sc: '67 '

(,

{

un: 'epesomiubtat ',

sc: '65 '

}

thecodeinthephpfilelookslikethis :

包括(connecttomysql.PHP );

$command='SELECT un,sc FROM xmlscores ORDER BY sc DESC ';

$ execute _ command=MySQL _ query ($ command;

echo '{ 'scores': ';

while ($ table _ row=MySQL _ fetch _ assoc ) $execute_command ) )

{

$jsonArray []=$table_row;

}

echoJSON_encode($JSONArray );

echo '} '

I

lookingatthephpfileandthejsonoutput,isthereanythingnoticeablywrongwithmycodesortheoutput? I can't figure it out。

解决方案' Cannot convert from Object to Array '

meansyouaretryingtoconvertresponsestringtojsonarray.butcurrentstringcontainsjsonobjectasrootelementinsteadofjsonarray.sococonaray

JSONObject json=new JSONObject (;

//get scores JSONArray from json

.

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。