Json/xml/POJO

Json与XML在线转换
http://www.bejson.com/go.php?u=http://www.bejson.com/xml2json/

Json在线转换为Java POJO类
http://www.bejson.com/json2javapojo/

Example:

1.多层嵌套的XML
<CCGW>           
	<CCGW_INFO>
		<serviceStatu>on</serviceStatu>
		<alive_stb_count>1</alive_stb_count>
	</CCGW_INFO>
	<STB_INFO_LIST>
		<STB_INFO>
			<stb_id>xxx1</stb_id>
			<stb_ip>0xc0a80886</stb_ip>
			<virtual_ip>0xaa80886</virtual_ip>
			<stb_mac>0x3e0f5ae1a501</stb_mac>
			<serviceGroup>5</serviceGroup>
			<session_id>0</session_id>
			<passwd>123456</passwd>
			<tuner_num>1</tuner_num>
			<tunerFrequencyArray>
				<tuner_index>0</tuner_index>
				<state>1</state>
				<freq_id>560000000</freq_id>
				<symbol_rate>6875</symbol_rate>
				<annex_mode>0</annex_mode>
				<qam_mode>0</qam_mode>
				<bandwidth>8</bandwidth>	
			</tunerFrequencyArray>
			<tunerFrequencyArray>
				<tuner_index>1</tuner_index>
				<state>1</state>
				<freq_id>560000000</freq_id>
				<symbol_rate>6875</symbol_rate>
				<annex_mode>0</annex_mode>
				<qam_mode>0</qam_mode>
				<bandwidth>8</bandwidth>
			</tunerFrequencyArray>
		</STB_INFO>
		<STB_INFO>
			<stb_id>xxx2</stb_id>
			<stb_ip>0xc0a80886</stb_ip>
			<virtual_ip>0xaa80886</virtual_ip>
			<stb_mac>0x3e0f5ae1a501</stb_mac>
			<serviceGroup>5</serviceGroup>
			<session_id>0</session_id>
			<passwd>123456</passwd>
			<tuner_num>1</tuner_num>
			<tunerFrequencyList>		
				<tunerFrequency>
					<tuner_index>0</tuner_index>
					<state>1</state>
					<freq_id>560000000</freq_id>
					<symbol_rate>6875</symbol_rate>
					<annex_mode>0</annex_mode>
					<qam_mode>0</qam_mode>
					<bandwidth>8</bandwidth>	
				</tunerFrequency>
				<tunerFrequency>
					<tuner_index>1</tuner_index>
					<state>1</state>
					<freq_id>560000000</freq_id>
					<symbol_rate>6875</symbol_rate>
					<annex_mode>0</annex_mode>
					<qam_mode>0</qam_mode>
					<bandwidth>8</bandwidth>
				</tunerFrequency>
			</tunerFrequencyList>
		</STB_INFO>
	</STB_INFO_LIST>

	<FREQ_INFO_LIST>
		<FREQ_INFO>
			<freq_id>560000000</freq_id>
			<symbol_rate>6875</symbol_rate>
			<annex_mode>0</annex_mode>
			<qam_mode>0</qam_mode>
			<original_bw>38</original_bw>
			<left_bw>30</left_bw>
			<freq_port_num>1</freq_port_num>
			<freqPortList>
				<freqPort>
					<port>258</port>
					<pn_id>2</pn_id>
					<bw>8</bw>
					<status>1</status>
				</freqPort>		
				<freqPort>
					<port>259</port>
					<pn_id>3</pn_id>
					<bw>8</bw>
					<status>1</status>
				</freqPort>
			</freqPortList>
		</FREQ_INFO>
		<FREQ_INFO>
			<freq_id>560000000</freq_id>
			<symbol_rate>6875</symbol_rate>
			<annex_mode>0</annex_mode>
			<qam_mode>0</qam_mode>
			<original_bw>38</original_bw>
			<left_bw>30</left_bw>
			<freq_port_num>1</freq_port_num>
			<freqPortList>
				<freqPort>
					<port>258</port>
					<pn_id>2</pn_id>
					<bw>8</bw>
					<status>1</status>
				</freqPort>		
				<freqPort>
					<port>259</port>
					<pn_id>3</pn_id>
					<bw>8</bw>
					<status>1</status>
				</freqPort>
			</freqPortList>
		</FREQ_INFO>
	</FREQ_INFO_LIST>
</CCGW>


2.转换为Json格式如下:
{
  "CCGW": {
    "CCGW_INFO": {
      "serviceStatu": "on",
      "alive_stb_count": "1"
    },
    "STB_INFO_LIST": {
      "STB_INFO": [
        {
          "stb_id": "xxx1",
          "stb_ip": "0xc0a80886",
          "virtual_ip": "0xaa80886",
          "stb_mac": "0x3e0f5ae1a501",
          "serviceGroup": "5",
          "session_id": "0",
          "passwd": "123456",
          "tuner_num": "1",
          "tunerFrequencyArray": [
            {
              "tuner_index": "0",
              "state": "1",
              "freq_id": "560000000",
              "symbol_rate": "6875",
              "annex_mode": "0",
              "qam_mode": "0",
              "bandwidth": "8"
            },
            {
              "tuner_index": "1",
              "state": "1",
              "freq_id": "560000000",
              "symbol_rate": "6875",
              "annex_mode": "0",
              "qam_mode": "0",
              "bandwidth": "8"
            }
          ]
        },
        {
          "stb_id": "xxx2",
          "stb_ip": "0xc0a80886",
          "virtual_ip": "0xaa80886",
          "stb_mac": "0x3e0f5ae1a501",
          "serviceGroup": "5",
          "session_id": "0",
          "passwd": "123456",
          "tuner_num": "1",
          "tunerFrequencyList": {
            "tunerFrequency": [
              {
                "tuner_index": "0",
                "state": "1",
                "freq_id": "560000000",
                "symbol_rate": "6875",
                "annex_mode": "0",
                "qam_mode": "0",
                "bandwidth": "8"
              },
              {
                "tuner_index": "1",
                "state": "1",
                "freq_id": "560000000",
                "symbol_rate": "6875",
                "annex_mode": "0",
                "qam_mode": "0",
                "bandwidth": "8"
              }
            ]
          }
        }
      ]
    },
    "FREQ_INFO_LIST": {
      "FREQ_INFO": [
        {
          "freq_id": "560000000",
          "symbol_rate": "6875",
          "annex_mode": "0",
          "qam_mode": "0",
          "original_bw": "38",
          "left_bw": "30",
          "freq_port_num": "1",
          "freqPortList": {
            "freqPort": [
              {
                "port": "258",
                "pn_id": "2",
                "bw": "8",
                "status": "1"
              },
              {
                "port": "259",
                "pn_id": "3",
                "bw": "8",
                "status": "1"
              }
            ]
          }
        },
        {
          "freq_id": "560000000",
          "symbol_rate": "6875",
          "annex_mode": "0",
          "qam_mode": "0",
          "original_bw": "38",
          "left_bw": "30",
          "freq_port_num": "1",
          "freqPortList": {
            "freqPort": [
              {
                "port": "258",
                "pn_id": "2",
                "bw": "8",
                "status": "1"
              },
              {
                "port": "259",
                "pn_id": "3",
                "bw": "8",
                "status": "1"
              }
            ]
          }
        }
      ]
    }
  }
}


3.再转换为Java POJO类,如下:
=================================

package;
public class CCGW_INFO {
	private String serviceStatu;

	private String alive_stb_count;

	public String setServiceStatu( String serviceStatu )
	{
		this.serviceStatu = serviceStatu;
	}


	public String setAlive_stb_count( String alive_stb_count )
	{
		this.alive_stb_count = alive_stb_count;
	}
}
== == == == == == == == == == == == == == == == =

package;
public class tunerFrequencyArray {
	private String tuner_index;

	private String state;

	private String freq_id;

	private String symbol_rate;

	private String annex_mode;

	private String qam_mode;

	private String bandwidth;

	public String setTuner_index( String tuner_index )
	{
		this.tuner_index = tuner_index;
	}


	public String setState( String state )
	{
		this.state = state;
	}


	public String setFreq_id( String freq_id )
	{
		this.freq_id = freq_id;
	}


	public String setSymbol_rate( String symbol_rate )
	{
		this.symbol_rate = symbol_rate;
	}


	public String setAnnex_mode( String annex_mode )
	{
		this.annex_mode = annex_mode;
	}


	public String setQam_mode( String qam_mode )
	{
		this.qam_mode = qam_mode;
	}


	public String setBandwidth( String bandwidth )
	{
		this.bandwidth = bandwidth;
	}
}
== == == == == == == == == == == == == == == == =

package;
import java.util.List;
public class STB_INFO {
	private String stb_id;

	private String stb_ip;

	private String virtual_ip;

	private String stb_mac;

	private String serviceGroup;

	private String session_id;

	private String passwd;

	private String tuner_num;

	private List<tunerFrequencyArray> tunerFrequencyArrays;

	public String setStb_id( String stb_id )
	{
		this.stb_id = stb_id;
	}


	public String setStb_ip( String stb_ip )
	{
		this.stb_ip = stb_ip;
	}


	public String setVirtual_ip( String virtual_ip )
	{
		this.virtual_ip = virtual_ip;
	}


	public String setStb_mac( String stb_mac )
	{
		this.stb_mac = stb_mac;
	}


	public String setServiceGroup( String serviceGroup )
	{
		this.serviceGroup = serviceGroup;
	}


	public String setSession_id( String session_id )
	{
		this.session_id = session_id;
	}


	public String setPasswd( String passwd )
	{
		this.passwd = passwd;
	}


	public String setTuner_num( String tuner_num )
	{
		this.tuner_num = tuner_num;
	}


	public List<tunerFrequencyArray> setTunerFrequencyArray( List<tunerFrequencyArray> tunerFrequencyArray )
	{
		this.tunerFrequencyArray = tunerFrequencyArray;
	}
}
== == == == == == == == == == == == == == == == =

package;
import java.util.List;
public class STB_INFO_LIST {
	private List<STB_INFO> STB_INFOs;

	public List<STB_INFO> setSTB_INFO( List<STB_INFO> STB_INFO )
	{
		this.STB_INFO = STB_INFO;
	}
}
== == == == == == == == == == == == == == == == =

package;
public class freqPort {
	private String port;

	private String pn_id;

	private String bw;

	private String status;

	public String setPort( String port )
	{
		this.port = port;
	}


	public String setPn_id( String pn_id )
	{
		this.pn_id = pn_id;
	}


	public String setBw( String bw )
	{
		this.bw = bw;
	}


	public String setStatus( String status )
	{
		this.status = status;
	}
}
== == == == == == == == == == == == == == == == =

package;
import java.util.List;
public class freqPortList {
	private List<freqPort> freqPorts;

	public List<freqPort> setFreqPort( List<freqPort> freqPort )
	{
		this.freqPort = freqPort;
	}
}
== == == == == == == == == == == == == == == == =

package;
public class FREQ_INFO {
	private String freq_id;

	private String symbol_rate;

	private String annex_mode;

	private String qam_mode;

	private String original_bw;

	private String left_bw;

	private String freq_port_num;

	private String freqPortList;

	public String setFreq_id( String freq_id )
	{
		this.freq_id = freq_id;
	}


	public String setSymbol_rate( String symbol_rate )
	{
		this.symbol_rate = symbol_rate;
	}


	public String setAnnex_mode( String annex_mode )
	{
		this.annex_mode = annex_mode;
	}


	public String setQam_mode( String qam_mode )
	{
		this.qam_mode = qam_mode;
	}


	public String setOriginal_bw( String original_bw )
	{
		this.original_bw = original_bw;
	}


	public String setLeft_bw( String left_bw )
	{
		this.left_bw = left_bw;
	}


	public String setFreq_port_num( String freq_port_num )
	{
		this.freq_port_num = freq_port_num;
	}


	public String setFreqPortList( String freqPortList )
	{
		this.freqPortList = freqPortList;
	}
}
== == == == == == == == == == == == == == == == =

package;
import java.util.List;
public class FREQ_INFO_LIST {
	private List<FREQ_INFO> FREQ_INFOs;

	public List<FREQ_INFO> setFREQ_INFO( List<FREQ_INFO> FREQ_INFO )
	{
		this.FREQ_INFO = FREQ_INFO;
	}
}
== == == == == == == == == == == == == == == == =

package;
public class CCGW {
	private String CCGW_INFO;

	private String STB_INFO_LIST;

	private String FREQ_INFO_LIST;

	public String setCCGW_INFO( String CCGW_INFO )
	{
		this.CCGW_INFO = CCGW_INFO;
	}


	public String setSTB_INFO_LIST( String STB_INFO_LIST )
	{
		this.STB_INFO_LIST = STB_INFO_LIST;
	}


	public String setFREQ_INFO_LIST( String FREQ_INFO_LIST )
	{
		this.FREQ_INFO_LIST = FREQ_INFO_LIST;
	}
}
== == == == == == == == == == == == == == == == =

package;
public class Root {
	private String CCGW;

	public String setCCGW( String CCGW )
	{
		this.CCGW = CCGW;
	}
}

备注:相应的POJO类需要自己在Eclipse等IDE工具中,重新设立getter/setter方法,部分类名改成大写!

附1: 在线Json格式化工具
http://www.5lulu.com/tec/Online_js.html
附2: 在线Java代码格式化工具
http://web.chacuo.net/formatjava



你可能感兴趣的:(Json XML POJO)