把ArrayList转化为json对象

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

最后输出:



  • 1
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

洛克-李

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值