ArrayList<Object> JSON

前端 未结 4 1821
执念已碎
执念已碎 2021-01-22 10:10

I am trying to return JSON data with my restlet. I can return a single item\'s JSON with..

import org.json.JSONObject;

Site aSite = new Site().getSite();   
JSO         


        
4条回答
  •  长发绾君心
    2021-01-22 10:58

    you have to add each item of the array as JSONObject as an index of the arraylist

    loop through your arraylist, creating jsonobjects where each element of your Site object is a key,value pair in your jsonobject

    and then add that jsonobject in your jsonarray's index

    for(int i = 0; i < allsites.length(); i++){
        ...
    }
    

提交回复
热议问题