在我的安卓应用程序,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
.