把ArrayList转化为json对象

阿里云国内75折 回扣 微信号:monov8
阿里云国际,腾讯云国际,低至75折。AWS 93折 免费开户实名账号 代冲值 优惠多多 微信号:monov8 飞机:@monov6


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;
    }
}


最后输出:

把ArrayList转化为json对象_java


阿里云国内75折 回扣 微信号:monov8
阿里云国际,腾讯云国际,低至75折。AWS 93折 免费开户实名账号 代冲值 优惠多多 微信号:monov8 飞机:@monov6