PageRenderTime 54ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/src/test/java/xjt/test/TestJson.java

https://bitbucket.org/xiejuntao/xdesktop
Java | 56 lines | 24 code | 6 blank | 26 comment | 0 complexity | 66e4fd9ca41b1eac99be1b22bf5b8b76 MD5 | raw file
  1. package xjt.test;
  2. import java.lang.reflect.ParameterizedType;
  3. import java.lang.reflect.Type;
  4. import java.util.ArrayList;
  5. import java.util.Date;
  6. import java.util.List;
  7. import com.alibaba.fastjson.JSON;
  8. import com.alibaba.fastjson.JSONObject;
  9. public class TestJson {
  10. public static void main(String[] args) {
  11. // List<String> list = new ArrayList<String>();
  12. // list.add("沉默");
  13. // list.add("结束");
  14. // list.add("一切");
  15. // System.out.println(JSON.toJSONString(list));
  16. List<CustomBean> beans = new ArrayList<CustomBean>();
  17. CustomBean customBean1 = new CustomBean();
  18. customBean1.setId(1);
  19. customBean1.setName("堕落");
  20. CustomBean customBean2 = new CustomBean();
  21. customBean2.setDate(new Date());
  22. customBean2.setId(2);
  23. customBean2.setName("夜");
  24. beans.add(customBean1);
  25. beans.add(customBean2);
  26. //System.out.println(beans.getClass());
  27. //if(s.getClass().equals(List.class)){
  28. //}
  29. //System.out.println(JSON.toJSONString(beans, true));
  30. String strs = JSON.toJSONString(beans);
  31. System.out.println(strs);
  32. // //List list = JSON.parseArray(strs, List.class);
  33. // //System.out.println(list);
  34. // if (ParameterizedType.class.isAssignableFrom(beans.getClass())) {
  35. // System.out.print("----------->getActualTypeArguments:");
  36. // for (Type t1:((ParameterizedType)beans).getActualTypeArguments()) {
  37. // System.out.println(t1 + ",");
  38. // }
  39. // }
  40. // int a = 1;
  41. // int b =2;
  42. // if(a==1){
  43. // System.out.println("aaaaaaaaaaaa");
  44. // }else if(b==2){
  45. // System.out.println("bbbbbbbbbbbbbbb");
  46. // }else{
  47. // System.out.println("ccccccccccc");
  48. // }
  49. }
  50. }