把java中的list对象转换成net.sf.JSONArray类型对象

package com.dean.test;
import java.util.ArrayList;
import java.util.List;

import com.dean.Address;

import net.sf.json.JSONArray;

public class Test {

    public static void main(String[] args) {
        Address address1 = new Address();
        address1.setNo("1068");
        address1.setProvince("桃源省");
        address1.setRoad("东篱路");
        address1.setStreet("南山街");
        Address address2 = new Address();
        address2.setNo("2046");
        address2.setProvince("陕西省");
        address2.setRoad("无名路");
        address2.setStreet("果壳街");
        List
addressList = new ArrayList
(); addressList.add(address1); addressList.add(address2); JSONArray jsonArr = JSONArray.fromObject(addressList); System.out.println(jsonArr); } }

你可能感兴趣的:(java)