把ArrayList转化为json对象

来源:互联网 发布:java编程框架 编辑:程序博客网 时间:2024/05/17 18:15
import java.util.ArrayList;//主类public class readHotel {public static void main(String[] args){//readHotelInformation();//distance_hotel(113.32344,23.11779);ArrayList<jsonHotel> hotel=new  ArrayList<jsonHotel>();  hotel.add(new jsonHotel("zhangsan","1","zhangsan","1","zhangsan","1","zhangsan","1","zhangsan","1","zhangsan"));   hotel.add(new jsonHotel("zhangsadsfn","1","zhaaaaangsan","1sdfsd","zhaadfngsan","1","zhansdfgsan","1","zhangsan","1","zhangsan"));             JSONArray result = JSONArray.fromObject(hotel);      System.out.println(result.toString(4));      //System.out.println(hotelMessage[0][1]+" "+hotelMessage[0][2]);}}


/** * 存放hotel信息,用来之后变成json格式传递的 * @author llq * */public class jsonHotel {        private String hotelName;      private String CommentAddress;    private String hotelWeb;      private String hotelAddress;    private String hotelLongitude;      private String hotelLatitude;    private String commentNumber;      private String hotelScore;    private String hotelPicture;      private String hotelPrice;    private String distance;      public jsonHotel(String hotelName, String CommentAddress,String hotelWeb,String hotelAddress,    String hotelLongitude,String hotelLatitude,String commentNumber,String hotelScore,    String hotelPicture,String hotelPrice,String distance) {       this.hotelName=hotelName;     this.CommentAddress=CommentAddress;     this.hotelWeb=hotelWeb;       this.hotelAddress=hotelAddress;     this.hotelLongitude=hotelLongitude;       this.hotelLatitude=hotelLatitude;     this.commentNumber=commentNumber;       this.hotelScore=hotelScore;     this.hotelPicture=hotelPicture;       this.hotelPrice=hotelPrice;     this.distance=distance;    }          public String getHotelName(){    return hotelName;    }    public String getCommentAddress(){    return CommentAddress;    }    public String getHotelWeb(){    return hotelWeb;    }    public String gethotelAddress(){    return hotelAddress;    }    public String getHotelLongitude(){    return hotelLongitude;    }    public String getHotelLatitude(){    return hotelLatitude;    }    public String getCommentNumber(){    return commentNumber;    }    public String getHotelScore(){    return hotelScore;    }    public String getHotelPicture(){    return hotelPicture;    }    public String getHotelPrice(){    return hotelPrice;    }    public String getDistance(){    return distance;    }}  

最后输出:



0 0
原创粉丝点击