把ArrayList转化为json对象,arraylistjson对象
分享于 点击 13235 次 点评:44
把ArrayList转化为json对象,arraylistjson对象
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;
}
}
最后输出:
相关文章
- 暂无相关文章
用户点评