package facadeTest.jsonTest;
import junit.framework.TestCase;
import net.sf.json.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.paic.pa18shop.auto.dto.common.QueryOrderParameterDTO;
/**
* 将对象转换成json字符串的几种方式 toJSONString使用的是import com.alibaba.fastjson.JSONObject
* jar包 JSONArray import net.sf.json.JSONArray
*/
public class JsonTest extends TestCase {
public void test() {
QueryOrderParameterDTO queryOrderParameterDTO = new QueryOrderParameterDTO();
queryOrderParameterDTO.setPolicyNo("sorry");
queryOrderParameterDTO.setProductCode("C01");
queryOrderParameterDTO.setSeriesNo("03");
// 获取queryOrderParaneterDTO对象
System.out.println(queryOrderParameterDTO);
// 获取set到queryOrderParaneterDTO对象中的值得json字符串
JSONObject json = new JSONObject();
String query = json.toJSONString(queryOrderParameterDTO);
System.out.println(query);
// 获取queryOrderParaneterDTO对象的json字符串
JSONArray js = JSONArray.fromObject(queryOrderParameterDTO);
String array = js.toString();
System.out.println(array);
}
}