json java读取 formbean操作

package test;

import entity.formBean;
import net.sf.json.JSONObject;



public class StrJson {
	
	public static void main(String[] args) {
		JSONObject js = JSONObject.fromObject("{'name':'zzh','color':['red','green']}");// 根据字符串转换对象 
		formBean bean = (formBean) JSONObject.toBean(js, formBean.class); // 把值绑定成相应的值对象 
		// 下面输出bean的值 
		System.out.println(bean.getName());
		for (String color : bean.getColor()) {
			System.out.println(color);
		}
	}
}
package entity;

public class formBean {
	private String name;
	private String[] color; 

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String[] getColor() {
		return color;
	}

	public void setColor(String[] color) {
		this.color = color;
	}
}

你可能感兴趣的:(java,json,bean,.net)