json字符串序列化工具

{
    "product": {
        "id": "16730",
        "title": "諾奇 韓版直筒修身仔褲 22111 幸運商城正品保障",
        "description": "http://ios.wolucky.com/Product/Detail.aspx?id=16730",
        "supplyid": "10138",
        "posttype": "2",
        "max": "149.00",
        "min": "149.00",
        "cprice": "329.00",
        "stock": [
            {
                "model": "28(2尺1)",
                "modelid": "64",
                "color": "藍色",
                "colorid": "23",
                "price": "149.00",
                "number": "10"
            },
            {
                "model": "29(2尺2)",
                "modelid": "65",
                "color": "藍色",
                "colorid": "23",
                "price": "149.00",
                "number": "10"
            },
            {
                "model": "30(2尺3)",
                "modelid": "66",
                "color": "藍色",
                "colorid": "23",
                "price": "149.00",
                "number": "10"
            },
            {
                "model": "31(2尺4)",
                "modelid": "67",
                "color": "藍色",
                "colorid": "23",
                "price": "149.00",
                "number": "10"
            },
            {
                "model": "32(2尺5)",
                "modelid": "68",
                "color": "藍色",
                "colorid": "23",
                "price": "149.00",
                "number": "10"
            },
            {
                "model": "33(2尺6)",
                "modelid": "69",
                "color": "藍色",
                "colorid": "23",
                "price": "149.00",
                "number": "10"
            },
            {
                "model": "34(2尺7)",
                "modelid": "70",
                "color": "藍色",
                "colorid": "23",
                "price": "149.00",
                "number": "10"
            },
            {
                "model": "35(2尺8)",
                "modelid": "71",
                "color": "藍色",
                "colorid": "23",
                "price": "149.00",
                "number": "10"
            },
            {
                "model": "36(2尺9)",
                "modelid": "72",
                "color": "藍色",
                "colorid": "23",
                "price": "149.00",
                "number": "10"
            },
            {
                "model": "38(3尺1)",
                "modelid": "353",
                "color": "藍色",
                "colorid": "23",
                "price": "149.00",
                "number": "10"
            },
            {
                "model": "40(3尺3)",
                "modelid": "355",
                "color": "藍色",
                "colorid": "23",
                "price": "149.00",
                "number": "10"
            },
            {
                "model": "42(3尺5)",
                "modelid": "357",
                "color": "藍色",
                "colorid": "23",
                "price": "149.00",
                "number": "10"
            }
        ],
        "imgs": [
            {
                "img": "http://img1.wolucky.com/Product/2013/10/08/b5b0fce3955248f4bbf4cc6f584db659.jpg_200.jpg"
            },
            {
                "img": "http://img1.wolucky.com/Product/2013/10/08/fe41cae8c2c04495986d3ad462d46812.jpg_200.jpg"
            },
            {
                "img": "http://img1.wolucky.com/Product/2013/10/08/3ece372b9e32459ca02b9c90804e666e.jpg_200.jpg"
            },
            {
                "img": "http://img1.wolucky.com/Product/2013/10/08/22e32844a00a4006ac71d06d3eb19628.jpg_200.jpg"
            }
        ],
        "property": [
            {
                "title": "品牌",
                "value": "諾奇"
            },
            {
                "title": "貨號",
                "value": "22111"
            },
            {
                "title": "顏色",
                "value": "藍色(L1)"
            },
            {
                "title": "褲長",
                "value": "長褲"
            },
            {
                "title": "牛仔面料",
                "value": "常規牛仔布"
            },
            {
                "title": "工藝處理",
                "value": "貓須 手擦 馬騮"
            },
            {
                "title": "款式細節",
                "value": "立體剪裁款"
            },
            {
                "title": "適用季節",
                "value": "四季"
            },
            {
                "title": "彈力指數",
                "value": "無彈"
            },
            {
                "title": "褲門襟",
                "value": "拉鍊"
            },
            {
                "title": "腰型",
                "value": "中腰"
            },
            {
                "title": "褲腳口",
                "value": "直腳/標準直腳"
            },
            {
                "title": "版型",
                "value": "修身型"
            },
            {
                "title": "厚薄",
                "value": "適中"
            },
            {
                "title": "消費羣體",
                "value": "青年"
            },
            {
                "title": "洗水",
                "value": "普通洗水"
            }
        ]
    }
}

格式化工具下載地址

http://download.csdn.net/detail/wangyg1990/6920835

裏面的index.html文件爲主運行框架。

有時候需要格式化請求的json字符串,通過格式化之後的json實體建立實體類。

上述複雜的json字符串通過格式化之後。如下圖



第一個實體類也就是大的總的實體類,而且實現了序列號接口,實例化之後就是可在intent 之間傳遞的對象實體。

/**
 * @category 商品詳情實體類
 * @author Administrator
 *
 */
public class ProductionDetail implements Serializable {
    
	public static final long serialVersionUID = 1L;
	public String id; 				// 商品地址
	public String title; 			// 商品簡單信息
	public String description; 		// 該處會跳轉到另一個頁面顯示商品詳情
	public String supplyid; 		// 商品編號
	public String posttype; 		// 配送方式1商家發送2商城發送
	public String max; 				// 最高價
	public String min; 				// 最低價
	public String cprice; 			// 原價
	public ArrayList<Stock> stocks;			//stock實體List
	public ArrayList<Img> imgs; 			// 所有圖片
	public ArrayList<Property> propertys;
	
	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	public String getTitle() {
		return title;
	}
	public void setTitle(String title) {
		this.title = title;
	}
	public String getDescription() {
		return description;
	}
	public void setDescription(String description) {
		this.description = description;
	}
	public String getSupplyid() {
		return supplyid;
	}
	public void setSupplyid(String supplyid) {
		this.supplyid = supplyid;
	}
	public String getPosttype() {
		return posttype;
	}
	public void setPosttype(String posttype) {
		this.posttype = posttype;
	}
	public String getMax() {
		return max;
	}
	public void setMax(String max) {
		this.max = max;
	}
	public String getMin() {
		return min;
	}
	public void setMin(String min) {
		this.min = min;
	}
	public String getCprice() {
		return cprice;
	}
	public void setCprice(String cprice) {
		this.cprice = cprice;
	}
	public ArrayList<Stock> getStocks() {
		return stocks;
	}
	public void setStocks(ArrayList<Stock> stocks) {
		this.stocks = stocks;
	}
	public ArrayList<Img> getImgs() {
		return imgs;
	}
	public void setImgs(ArrayList<Img> imgs) {
		this.imgs = imgs;
	}
	public static long getSerialversionuid() {
		return serialVersionUID;
	}
	
	//toString 方法
	@Override
	public String toString() {
		return "ProductionDetail [id=" + id + ", title=" + title
				+ ", description=" + description + ", supplyid=" + supplyid
				+ ", posttype=" + posttype + ", max=" + max + ", min=" + min
				+ ", cprice=" + cprice + ", stocks=" + stocks + ", imgs="
				+ imgs + "]";
	}
          
	
}


第二個實體是要實現stock實體,緊接着,Img實體,Property實體。


/**
 * @author 王亞光
 * @category 產品詳情庫存 ArrayList<Stock>的stock實體類
 */
public class Stock implements Serializable{
	private static final long serialVersionUID = 1L;
	public String model; 		// 尺寸
	public String modelid; 	//尺寸id
	public String color; 		// 顏色
	public String colorid; 	//顏色id
	public String price; 		// 價格
	public String number; 		// 庫存


	@Override
	public String toString() {
		return "Stock [model=" + model + ", modelid=" + modelid + ", color="
				+ color + ", colorid=" + colorid + ", price=" + price
				+ ", number=" + number + "]";
	}
	public String getModel() {
		return model;
	}
	public void setModel(String model) {
		this.model = model;
	}
	public String getModelid() {
		return modelid;
	}
	public void setModelid(String modelid) {
		this.modelid = modelid;
	}
	public String getColor() {
		return color;
	}
	public void setColor(String color) {
		this.color = color;
	}
	public String getColorid() {
		return colorid;
	}
	public void setColorid(String colorid) {
		this.colorid = colorid;
	}
	public String getPrice() {
		return price;
	}
	public void setPrice(String price) {
		this.price = price;
	}
	public String getNumber() {
		return number;
	}
	public void setNumber(String number) {
		this.number = number;
	}
}

/**
 * @category 該類是img實體類
 * @author 王亞光
 */
public class Img implements Serializable{




	private static final long serialVersionUID = 1L;
	//單個圖片
	public  String img;          


	public String getImg() {
		return img;
	}


	public void setImg(String img) {
		this.img = img;
	}


	@Override
	public String toString() {
		return "Img [img=" + img + "]";
	}


}

public class Property implements Serializable{
	private static final long serialVersionUID = 1L;
	public String title;
	public String value;
	
	@Override
	public String toString() {
		return "Property [title=" + title + ", value=" + value + "]";
	}
	public String getTitle() {
		return title;
	}
	public void setTitle(String title) {
		this.title = title;
	}
	public String getValue() {
		return value;
	}
	public void setValue(String value) {
		this.value = value;
	}
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章