简体   繁体   中英

error org.json.JSONObject cannot be converted to JSONArray

I have a php file for my android project. I want it to show the array data from my php codes. but it show the error like "error parsing data org.json.JSONException ... error org.json.JSONObject cannot be converted to JSONArray"

Here's the php codes :

  $rows = array();

            $rows['nama_makanan'] = "you have yet to input";
            $rows['Jtakaran'] = "-";
            $data = "{food:".json_encode($rows)."}";
        echo $data; 

I'm guessing the error is in the php code. because when I try to retrieve data from mysql the program is working fine. I'm sorry for my bad English . Any help would be appreciated, thank you

ps : I want the data to retrieve as JSONArray because this is for expanadablelistview.

echo json_encode(array("food", $rows));

check my answer on

How to decode JSON values in my Android Aplication?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM