歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> Android輕量級JSON序列化和反序列化

Android輕量級JSON序列化和反序列化

日期:2017/3/1 10:32:12   编辑:Linux編程
最近開發一直使用JSON數據傳輸,網絡中流程的JSON解析導入包太多了,在網上找了下,結合自己改編,簡單實現JSON解析,支持集合和對象泛化。 [java]
  1. package com.callgetway.util;
  2. import java.lang.reflect.Array;
  3. import java.lang.reflect.Field;
  4. import java.lang.reflect.Method;
  5. import java.lang.reflect.ParameterizedType;
  6. import java.lang.reflect.Type;
  7. import java.text.SimpleDateFormat;
  8. import java.util.Collection;
  9. import java.util.Date;
  10. import java.util.HashMap;
  11. import java.util.Iterator;
  12. import java.util.List;
  13. import java.util.Locale;
  14. import java.util.Map;
  15. import org.json.JSONArray;
  16. import org.json.JSONException;
  17. import org.json.JSONObject;
  18. import org.json.JSONStringer;
  19. import Android.util.Log;
  20. /**
  21. * @author keane
  22. * @version 1.0
  23. *
  24. */
  25. public class JSONHelper {
  26. private static String TAG = "JSONHelper";
  27. /**
  28. * 將對象轉換成Json字符串
  29. * @param obj
  30. * @return
  31. */
  32. public static String toJSON(Object obj) {
  33. JSONStringer js = new JSONStringer();
  34. serialize(js, obj);
  35. Log.d(TAG, "JSONHelper toJSON :" + js.toString());
  36. return js.toString();
  37. }
  38. /**
  39. * 序列化為JSON
  40. * @param js
  41. * @param o
  42. */
  43. private static void serialize(JSONStringer js, Object o) {
  44. if (isNull(o)) {
  45. try {
  46. js.value(null);
  47. } catch (JSONException e) {
  48. e.printStackTrace();
  49. }
  50. return;
  51. }
  52. Class<?> clazz = o.getClass();
  53. if (isObject(clazz)) { // 對象
  54. serializeObject(js, o);
  55. } else if (isArray(clazz)) { // 數組
  56. serializeArray(js, o);
  57. } else if (isCollection(clazz)) { // 集合
  58. Collection<?> collection = (Collection<?>) o;
  59. serializeCollect(js, collection);
  60. } else { // 單個值
  61. try {
  62. js.value(o);
  63. } catch (JSONException e) {
  64. e.printStackTrace();
  65. }
  66. }
  67. }
  68. /**
  69. * 序列化數組
  70. * @param js
  71. * @param array
  72. */
  73. private static void serializeArray(JSONStringer js, Object array) {
  74. try {
  75. js.array();
  76. for (int i = 0; i < Array.getLength(array); ++i) {
  77. Object o = Array.get(array, i);
  78. serialize(js, o);
  79. }
  80. js.endArray();
  81. } catch (Exception e) {
  82. e.printStackTrace();
  83. }
  84. }
  85. /**
  86. * 序列化集合
  87. * @param js
  88. * @param collection
  89. */
  90. private static void serializeCollect(JSONStringer js, Collection<?> collection) {
  91. try {
  92. js.array();
  93. for (Object o : collection) {
  94. serialize(js, o);
  95. }
  96. js.endArray();
  97. } catch (Exception e) {
  98. e.printStackTrace();
  99. }
  100. }
  101. /**
  102. * 序列化對象
  103. * @param js
  104. * @param obj
  105. */
  106. private static void serializeObject(JSONStringer js, Object obj) {
  107. try {
  108. js.object();
  109. Class<? extends Object> objClazz = obj.getClass();
  110. Method[] methods = objClazz.getDeclaredMethods();
  111. Field[] fields = objClazz.getDeclaredFields();
  112. for (Field field : fields) {
  113. try {
  114. String fieldType = field.getType().getSimpleName();
  115. String fieldGetName = parseMethodName(field.getName(),"get");
  116. if (!haveMethod(methods, fieldGetName)) {
  117. continue;
  118. }
  119. Method fieldGetMet = objClazz.getMethod(fieldGetName, new Class[] {});
  120. Object fieldVal = fieldGetMet.invoke(obj, new Object[] {});
  121. String result = null;
  122. if ("Date".equals(fieldType)) {
  123. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss",
  124. Locale.US);
  125. result = sdf.format((Date)fieldVal);
  126. } else {
  127. if (null != fieldVal) {
  128. result = String.valueOf(fieldVal);
  129. }
  130. }
  131. js.key(field.getName());
  132. serialize(js, result);
  133. } catch (Exception e) {
  134. continue;
  135. }
  136. }
  137. js.endObject();
  138. } catch (Exception e) {
  139. e.printStackTrace();
  140. }
  141. }
  142. /**
  143. * 判斷是否存在某屬性的 get方法
  144. *
  145. * @param methods
  146. * @param fieldGetMet
  147. * @return boolean
  148. */
  149. public static boolean haveMethod(Method[] methods, String fieldMethod) {
  150. for (Method met : methods) {
  151. if (fieldMethod.equals(met.getName())) {
  152. return true;
  153. }
  154. }
  155. return false;
  156. }
  157. /**
  158. * 拼接某屬性的 get或者set方法
  159. * @param fieldName
  160. * @param methodType
  161. * @return
  162. */
  163. public static String parseMethodName(String fieldName,String methodType) {
  164. if (null == fieldName || "".equals(fieldName)) {
  165. return null;
  166. }
  167. return methodType + fieldName.substring(0, 1).toUpperCase()
  168. + fieldName.substring(1);
  169. }
  170. /**
  171. * set屬性的值到Bean
  172. * @param obj
  173. * @param valMap
  174. */
  175. public static void setFieldValue(Object obj, Map<String, String> valMap) {
  176. Class<?> cls = obj.getClass();
  177. // 取出bean裡的所有方法
  178. Method[] methods = cls.getDeclaredMethods();
  179. Field[] fields = cls.getDeclaredFields();
  180. for (Field field : fields) {
  181. try {
  182. String setMetodName = parseMethodName(field.getName(),"set");
  183. if (!haveMethod(methods, setMetodName)) {
  184. continue;
  185. }
  186. Method fieldMethod = cls.getMethod(setMetodName, field
  187. .getType());
  188. String value = valMap.get(field.getName());
  189. if (null != value && !"".equals(value)) {
  190. String fieldType = field.getType().getSimpleName();
  191. if ("String".equals(fieldType)) {
  192. fieldMethod.invoke(obj, value);
  193. } else if ("Date".equals(fieldType)) {
  194. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss",Locale.US);
  195. Date temp = sdf.parse(value);
  196. fieldMethod.invoke(obj, temp);
  197. } else if ("Integer".equals(fieldType)
  198. || "int".equals(fieldType)) {
  199. Integer intval = Integer.parseInt(value);
  200. fieldMethod.invoke(obj, intval);
  201. } else if ("Long".equalsIgnoreCase(fieldType)) {
  202. Long temp = Long.parseLong(value);
  203. fieldMethod.invoke(obj, temp);
  204. } else if ("Double".equalsIgnoreCase(fieldType)) {
  205. Double temp = Double.parseDouble(value);
  206. fieldMethod.invoke(obj, temp);
  207. } else if ("Boolean".equalsIgnoreCase(fieldType)) {
  208. Boolean temp = Boolean.parseBoolean(value);
  209. fieldMethod.invoke(obj, temp);
  210. } else {
  211. System.out.println("setFieldValue not supper type:" + fieldType);
  212. }
  213. }
  214. } catch (Exception e) {
  215. continue;
  216. }
  217. }
  218. }
  219. /**
  220. * 對象轉Map
  221. * @param obj
  222. * @return
  223. */
  224. public static Map<String, String> getFieldValueMap(Object obj) {
  225. Class<?> cls = obj.getClass();
  226. Map<String, String> valueMap = new HashMap<String, String>();
  227. // 取出bean裡的所有方法
  228. Method[] methods = cls.getDeclaredMethods();
  229. Field[] fields = cls.getDeclaredFields();
  230. for (Field field : fields) {
  231. try {
  232. String fieldType = field.getType().getSimpleName();
  233. String fieldGetName = parseMethodName(field.getName(),"get");
  234. if (!haveMethod(methods, fieldGetName)) {
  235. continue;
  236. }
  237. Method fieldGetMet = cls.getMethod(fieldGetName, new Class[] {});
  238. Object fieldVal = fieldGetMet.invoke(obj, new Object[] {});
  239. String result = null;
  240. if ("Date".equals(fieldType)) {
  241. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss",Locale.CHINA);
  242. result = sdf.format((Date)fieldVal);
  243. } else {
  244. if (null != fieldVal) {
  245. result = String.valueOf(fieldVal);
  246. }
  247. }
  248. valueMap.put(field.getName(), result);
  249. } catch (Exception e) {
  250. continue;
  251. }
  252. }
  253. return valueMap;
  254. }
  255. /**
  256. * 給對象的字段賦值
  257. * @param obj
  258. * @param fieldSetMethod
  259. * @param fieldType
  260. * @param value
  261. */
  262. public static void setFiedlValue(Object obj,Method fieldSetMethod,String fieldType,Object value){
  263. try {
  264. if (null != value && !"".equals(value)) {
  265. if ("String".equals(fieldType)) {
  266. fieldSetMethod.invoke(obj, value.toString());
  267. } else if ("Date".equals(fieldType)) {
  268. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss",Locale.CHINA);
  269. Date temp = sdf.parse(value.toString());
  270. fieldSetMethod.invoke(obj, temp);
  271. } else if ("Integer".equals(fieldType)
  272. || "int".equals(fieldType)) {
  273. Integer intval = Integer.parseInt(value.toString());
  274. fieldSetMethod.invoke(obj, intval);
  275. } else if ("Long".equalsIgnoreCase(fieldType)) {
  276. Long temp = Long.parseLong(value.toString());
  277. fieldSetMethod.invoke(obj, temp);
  278. } else if ("Double".equalsIgnoreCase(fieldType)) {
  279. Double temp = Double.parseDouble(value.toString());
  280. fieldSetMethod.invoke(obj, temp);
  281. } else if ("Boolean".equalsIgnoreCase(fieldType)) {
  282. Boolean temp = Boolean.parseBoolean(value.toString());
  283. fieldSetMethod.invoke(obj, temp);
  284. } else {
  285. fieldSetMethod.invoke(obj, value);
  286. Log.e(TAG, TAG + ">>>>setFiedlValue -> not supper type" + fieldType);
  287. }
  288. }
  289. } catch (Exception e) {
  290. Log.e(TAG, TAG + ">>>>>>>>>>set value error.",e);
  291. }
  292. }
  293. /**
  294. * 反序列化簡單對象
  295. * @param jo
  296. * @param clazz
  297. * @return
  298. */
  299. public static <T> T parseObject(JSONObject jo, Class<T> clazz) {
  300. if (clazz == null || isNull(jo)) {
  301. return null;
  302. }
  303. T obj = newInstance(clazz);
  304. if (obj == null) {
  305. return null;
  306. }
  307. if(isMap(clazz)){
  308. setField(obj,jo);
  309. }else{
  310. // 取出bean裡的所有方法
  311. Method[] methods = clazz.getDeclaredMethods();
  312. Field[] fields = clazz.getDeclaredFields();
  313. for (Field f : fields) {
  314. String setMetodName = parseMethodName(f.getName(),"set");
  315. if (!haveMethod(methods, setMetodName)) {
  316. continue;
  317. }
  318. try {
  319. Method fieldMethod = clazz.getMethod(setMetodName, f.getType());
  320. setField(obj,fieldMethod,f, jo);
  321. } catch (Exception e) {
  322. e.printStackTrace();
  323. }
  324. }
  325. }
  326. return obj;
  327. }
  328. /**
  329. * 反序列化簡單對象
  330. * @param jsonString
  331. * @param clazz
  332. * @return
  333. */
  334. public static <T> T parseObject(String jsonString, Class<T> clazz) {
  335. if (clazz == null || jsonString == null || jsonString.length() == 0) {
  336. return null;
  337. }
  338. JSONObject jo = null;
  339. try {
  340. jo = new JSONObject(jsonString);
  341. } catch (JSONException e) {
  342. e.printStackTrace();
  343. }
  344. if (isNull(jo)) {
  345. return null;
  346. }
  347. return parseObject(jo, clazz);
  348. }
  349. /**
  350. * 反序列化數組對象
  351. * @param ja
  352. * @param clazz
  353. * @return
  354. */
  355. public static <T> T[] parseArray(JSONArray ja, Class<T> clazz) {
  356. if (clazz == null || isNull(ja)) {
  357. return null;
  358. }
  359. int len = ja.length();
  360. @SuppressWarnings("unchecked")
  361. T[] array = (T[]) Array.newInstance(clazz, len);
  362. for (int i = 0; i < len; ++i) {
  363. try {
  364. JSONObject jo = ja.getJSONObject(i);
  365. T o = parseObject(jo, clazz);
  366. array[i] = o;
  367. } catch (JSONException e) {
  368. e.printStackTrace();
  369. }
  370. }
  371. return array;
  372. }
  373. /**
  374. * 反序列化數組對象
  375. * @param jsonString
  376. * @param clazz
  377. * @return
  378. */
  379. public static <T> T[] parseArray(String jsonString, Class<T> clazz) {
  380. if (clazz == null || jsonString == null || jsonString.length() == 0) {
  381. return null;
  382. }
  383. JSONArray jo = null;
  384. try {
  385. jo = new JSONArray(jsonString);
  386. } catch (JSONException e) {
  387. e.printStackTrace();
  388. }
  389. if (isNull(jo)) {
  390. return null;
  391. }
  392. return parseArray(jo, clazz);
  393. }
  394. /**
  395. * 反序列化泛型集合
  396. * @param ja
  397. * @param collectionClazz
  398. * @param genericType
  399. * @return
  400. */
  401. @SuppressWarnings("unchecked")
  402. public static <T> Collection<T> parseCollection(JSONArray ja, Class<?> collectionClazz,
  403. Class<T> genericType) {
  404. if (collectionClazz == null || genericType == null || isNull(ja)) {
  405. return null;
  406. }
  407. Collection<T> collection = (Collection<T>) newInstance(collectionClazz);
  408. for (int i = 0; i < ja.length(); ++i) {
  409. try {
  410. JSONObject jo = ja.getJSONObject(i);
  411. T o = parseObject(jo, genericType);
  412. collection.add(o);
  413. } catch (JSONException e) {
  414. e.printStackTrace();
  415. }
  416. }
  417. return collection;
  418. }
  419. /**
  420. * 反序列化泛型集合
  421. * @param jsonString
  422. * @param collectionClazz
  423. * @param genericType
  424. * @return
  425. */
  426. public static <T> Collection<T> parseCollection(String jsonString, Class<?> collectionClazz,
  427. Class<T> genericType) {
  428. if (collectionClazz == null || genericType == null || jsonString == null
  429. || jsonString.length() == 0) {
  430. return null;
  431. }
  432. JSONArray jo = null;
  433. try {
  434. jo = new JSONArray(jsonString);
  435. } catch (JSONException e) {
  436. e.printStackTrace();
  437. }
  438. if (isNull(jo)) {
  439. return null;
  440. }
  441. return parseCollection(jo, collectionClazz, genericType);
  442. }
  443. /**
  444. * 根據類型創建對象
  445. * @param clazz
  446. * @return
  447. */
  448. private static <T> T newInstance(Class<T> clazz) {
  449. if (clazz == null)
  450. return null;
  451. T obj = null;
  452. try {
  453. obj = clazz.newInstance();
  454. } catch (Exception e) {
  455. e.printStackTrace();
  456. }
  457. return obj;
  458. }
  459. /**
  460. * 設定Map的值
  461. * @param obj
  462. * @param jo
  463. */
  464. private static void setField(Object obj, JSONObject jo) {
  465. try {
  466. @SuppressWarnings("unchecked")
  467. Iterator<String> keyIter = jo.keys();
  468. String key;
  469. Object value;
  470. @SuppressWarnings("unchecked")
  471. Map<String, Object> valueMap = (Map<String, Object>) obj;
  472. while (keyIter.hasNext()) {
  473. key = (String) keyIter.next();
  474. value = jo.get(key);
  475. valueMap.put(key, value);
  476. }
  477. } catch (JSONException e) {
  478. e.printStackTrace();
  479. }
  480. }
  481. /**
  482. * 設定字段的值
  483. * @param obj
  484. * @param fieldSetMethod
  485. * @param f
  486. * @param jo
  487. */
  488. private static void setField(Object obj, Method fieldSetMethod,Field f, JSONObject jo) {
  489. String name = f.getName();
  490. Class<?> clazz = f.getType();
  491. try {
  492. if (isArray(clazz)) { // 數組
  493. Class<?> c = clazz.getComponentType();
  494. JSONArray ja = jo.optJSONArray(name);
  495. if (!isNull(ja)) {
  496. Object array = parseArray(ja, c);
  497. setFiedlValue(obj, fieldSetMethod, clazz.getSimpleName(), array);
  498. }
  499. } else if (isCollection(clazz)) { // 泛型集合
  500. // 獲取定義的泛型類型
  501. Class<?> c = null;
  502. Type gType = f.getGenericType();
  503. if (gType instanceof ParameterizedType) {
  504. ParameterizedType ptype = (ParameterizedType) gType;
  505. Type[] targs = ptype.getActualTypeArguments();
  506. if (targs != null && targs.length > 0) {
  507. Type t = targs[0];
  508. c = (Class<?>) t;
  509. }
  510. }
  511. JSONArray ja = jo.optJSONArray(name);
  512. if (!isNull(ja)) {
  513. Object o = parseCollection(ja, clazz, c);
  514. setFiedlValue(obj, fieldSetMethod, clazz.getSimpleName(), o);
  515. }
  516. } else if (isSingle(clazz)) { // 值類型
  517. Object o = jo.opt(name);
  518. if (o != null) {
  519. setFiedlValue(obj, fieldSetMethod, clazz.getSimpleName(), o);
  520. }
  521. } else if (isObject(clazz)) { // 對象
  522. JSONObject j = jo.optJSONObject(name);
  523. if (!isNull(j)) {
  524. Object o = parseObject(j, clazz);
  525. setFiedlValue(obj, fieldSetMethod, clazz.getSimpleName(), o);
  526. }
  527. } else if (isList(clazz)) { // 列表
  528. // JSONObject j = jo.optJSONObject(name);
  529. // if (!isNull(j)) {
  530. // Object o = parseObject(j, clazz);
  531. // f.set(obj, o);
  532. // }
  533. } else {
  534. throw new Exception("unknow type!");
  535. }
  536. } catch (Exception e) {
  537. e.printStackTrace();
  538. }
  539. }
  540. /**
  541. * 設定字段的值
  542. * @param obj
  543. * @param f
  544. * @param jo
  545. */
  546. private static void setField(Object obj, Field f, JSONObject jo) {
  547. String name = f.getName();
  548. Class<?> clazz = f.getType();
  549. try {
  550. if (isArray(clazz)) { // 數組
  551. Class<?> c = clazz.getComponentType();
  552. JSONArray ja = jo.optJSONArray(name);
  553. if (!isNull(ja)) {
  554. Object array = parseArray(ja, c);
  555. f.set(obj, array);
  556. }
  557. } else if (isCollection(clazz)) { // 泛型集合
  558. // 獲取定義的泛型類型
  559. Class<?> c = null;
  560. Type gType = f.getGenericType();
  561. if (gType instanceof ParameterizedType) {
  562. ParameterizedType ptype = (ParameterizedType) gType;
  563. Type[] targs = ptype.getActualTypeArguments();
  564. if (targs != null && targs.length > 0) {
  565. Type t = targs[0];
  566. c = (Class<?>) t;
  567. }
  568. }
  569. JSONArray ja = jo.optJSONArray(name);
  570. if (!isNull(ja)) {
  571. Object o = parseCollection(ja, clazz, c);
  572. f.set(obj, o);
  573. }
  574. } else if (isSingle(clazz)) { // 值類型
  575. Object o = jo.opt(name);
  576. if (o != null) {
  577. f.set(obj, o);
  578. }
  579. } else if (isObject(clazz)) { // 對象
  580. JSONObject j = jo.optJSONObject(name);
  581. if (!isNull(j)) {
  582. Object o = parseObject(j, clazz);
  583. f.set(obj, o);
  584. }
  585. } else if (isList(clazz)) { // 列表
  586. JSONObject j = jo.optJSONObject(name);
  587. if (!isNull(j)) {
  588. Object o = parseObject(j, clazz);
  589. f.set(obj, o);
  590. }
  591. }else {
  592. throw new Exception("unknow type!");
  593. }
  594. } catch (Exception e) {
  595. e.printStackTrace();
  596. }
  597. }
  598. /**
  599. * 判斷對象是否為空
  600. * @param obj
  601. * @return
  602. */
  603. private static boolean isNull(Object obj) {
  604. if (obj instanceof JSONObject) {
  605. return JSONObject.NULL.equals(obj);
  606. }
  607. return obj == null;
  608. }
  609. /**
  610. * 判斷是否是值類型
  611. * @param clazz
  612. * @return
  613. */
  614. private static boolean isSingle(Class<?> clazz) {
  615. return isBoolean(clazz) || isNumber(clazz) || isString(clazz);
  616. }
  617. /**
  618. * 是否布爾值
  619. * @param clazz
  620. * @return
  621. */
  622. public static boolean isBoolean(Class<?> clazz) {
  623. return (clazz != null)
  624. && ((Boolean.TYPE.isAssignableFrom(clazz)) || (Boolean.class
  625. .isAssignableFrom(clazz)));
  626. }
  627. /**
  628. * 是否數值
  629. * @param clazz
  630. * @return
  631. */
  632. public static boolean isNumber(Class<?> clazz) {
  633. return (clazz != null)
  634. && ((Byte.TYPE.isAssignableFrom(clazz)) || (Short.TYPE.isAssignableFrom(clazz))
  635. || (Integer.TYPE.isAssignableFrom(clazz))
  636. || (Long.TYPE.isAssignableFrom(clazz))
  637. || (Float.TYPE.isAssignableFrom(clazz))
  638. || (Double.TYPE.isAssignableFrom(clazz)) || (Number.class
  639. .isAssignableFrom(clazz)));
  640. }
  641. /**
  642. * 判斷是否是字符串
  643. * @param clazz
  644. * @return
  645. */
  646. public static boolean isString(Class<?> clazz) {
  647. return (clazz != null)
  648. && ((String.class.isAssignableFrom(clazz))
  649. || (Character.TYPE.isAssignableFrom(clazz)) || (Character.class
  650. .isAssignableFrom(clazz)));
  651. }
  652. /**
  653. * 判斷是否是對象
  654. * @param clazz
  655. * @return
  656. */
  657. private static boolean isObject(Class<?> clazz) {
  658. return clazz != null && !isSingle(clazz) && !isArray(clazz) && !isCollection(clazz);
  659. }
  660. /**
  661. * 判斷是否是數組
  662. * @param clazz
  663. * @return
  664. */
  665. public static boolean isArray(Class<?> clazz) {
  666. return clazz != null && clazz.isArray();
  667. }
  668. /**
  669. * 判斷是否是集合
  670. * @param clazz
  671. * @return
  672. */
  673. public static boolean isCollection(Class<?> clazz) {
  674. return clazz != null && Collection.class.isAssignableFrom(clazz);
  675. }
  676. /**
  677. * 判斷是否是Map
  678. * @param clazz
  679. * @return
  680. */
  681. public static boolean isMap(Class<?> clazz) {
  682. return clazz != null && Map.class.isAssignableFrom(clazz);
  683. }
  684. /**
  685. * 判斷是否是列表
  686. * @param clazz
  687. * @return
  688. */
  689. public static boolean isList(Class<?> clazz) {
  690. return clazz != null && List.class.isAssignableFrom(clazz);
  691. }
  692. }

測試代碼:

[java]
  1. public class User{
  2. private String name;
  3. private String password;
  4. public String getName() {
  5. return name;
  6. }
  7. public void setName(String name) {
  8. this.name = name;
  9. }
  10. public String getPassword() {
  11. return password;
  12. }
  13. public void setPassword(String password) {
  14. this.password = password;
  15. }
  16. }
  17. void testObj(){
  18. User user = new User();
  19. user.setName("abcd");
  20. user.setPassword("123456");
  21. String jsonStrUser = JSONHelper.toJSON(user);
  22. User jsonUser = JSONHelper.parseObject(jsonStrUser, User.class);
  23. Map mapUser = JSONHelper.parseObject(jsonStrUser, HashMap.class);
  24. }
Copyright © Linux教程網 All Rights Reserved