1,String ---->  Uri

Uri uri = Uri.parse((String) str);

例如: str = “content://*******”

str = "file://**********"

str = "http://*************"

str = "ftp://***********"


2,Uri   ----->  String

String str = uri.toString();




 GSON 是一个 Java 类库,可以把 Java 对象转换成 JSON 数据,也可以把 JSON 字符串转换成 Java 对象,支持任意复杂的 

Java 对象,包括没有源代码的对象。


  1. public class GsonTools {  
  2.   
  3.     public GsonTools() {  
  4.     }  
  5.   
  6.     public static <T> T getPerson(String jsonString, Class<T> cls) {  
  7.         T t = null;  
  8.         try {  
  9.             Gson gson = new Gson();  
  10.             t = gson.fromJson(jsonString, cls);  
  11.         } catch (Exception e) {  
  12.             e.printStackTrace();  
  13.         }  
  14.         return t;  
  15.     }  
  16.   
  17.     public static <T> List<T> getPersons(String jsonString, Class<T> cls) {  
  18.         List<T> list = new ArrayList<T>();  
  19.         try {  
  20.             Gson gson = new Gson();  
  21.             list = gson.fromJson(jsonString, new TypeToken<List<T>>() {  
  22.             }.getType());  
  23.         } catch (Exception e) {  
  24.             e.printStackTrace();  
  25.         }  
  26.         return list;  
  27.     }  
  28.   
  29.     public static List<String> getList(String jsonString) {  
  30.         List<String> list = new ArrayList<String>();  
  31.         try {  
  32.             Gson gson = new Gson();  
  33.             list = gson.fromJson(jsonString, new TypeToken<List<String>>() {  
  34.             }.getType());  
  35.         } catch (Exception e) {  
  36.             e.printStackTrace();  
  37.         }  
  38.         return list;  
  39.     }  
  40.   
  41.     public static List<Map<String, Object>> listKeyMaps(String jsonString) {  
  42.         List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();  
  43.         try {  
  44.             Gson gson = new Gson();  
  45.             list = gson.fromJson(jsonString, new TypeToken<List<Map<String, Object>>>() {  
  46.             }.getType());  
  47.         } catch (Exception e) {  
  48.             e.printStackTrace();  
  49.         }  
  50.         return list;  
  51.     }  
  52.   
  53. }  

Map<String,Object> map = new HashMap<String,Object>();
map.put("sex", type);
map.put("marriage", marriage);
map.put("education", education);
map.put("origin", locationStr);
map.put("address", nowAddressStr + "" + detailsAddressStr);
map.put("contact1", contact1);
map.put("contact1Name", nameStr);
map.put("contact1Phone", phoneStr);
map.put("contact2", contact2);
map.put("contact2Name", nameDownStr);
map.put("contact2Phone", phoneDownStr);
map.put("personalProperty", personalProperty);
map.put("vocation", vocationStr);

Gson gson=new Gson();
String s = gson.toJson(map);



 GSON 是一个 Java 类库,可以把 Java 对象转换成 JSON 数据,也可以把 JSON 字符串转换成 Java 对象,支持任意复杂的 

Java 对象,包括没有源代码的对象。


  1. public class GsonTools {  
  2.   
  3.     public GsonTools() {  
  4.     }  
  5.   
  6.     public static <T> T getPerson(String jsonString, Class<T> cls) {  
  7.         T t = null;  
  8.         try {  
  9.             Gson gson = new Gson();  
  10.             t = gson.fromJson(jsonString, cls);  
  11.         } catch (Exception e) {  
  12.             e.printStackTrace();  
  13.         }  
  14.         return t;  
  15.     }  
  16.   
  17.     public static <T> List<T> getPersons(String jsonString, Class<T> cls) {  
  18.         List<T> list = new ArrayList<T>();  
  19.         try {  
  20.             Gson gson = new Gson();  
  21.             list = gson.fromJson(jsonString, new TypeToken<List<T>>() {  
  22.             }.getType());  
  23.         } catch (Exception e) {  
  24.             e.printStackTrace();  
  25.         }  
  26.         return list;  
  27.     }  
  28.   
  29.     public static List<String> getList(String jsonString) {  
  30.         List<String> list = new ArrayList<String>();  
  31.         try {  
  32.             Gson gson = new Gson();  
  33.             list = gson.fromJson(jsonString, new TypeToken<List<String>>() {  
  34.             }.getType());  
  35.         } catch (Exception e) {  
  36.             e.printStackTrace();  
  37.         }  
  38.         return list;  
  39.     }  
  40.   
  41.     public static List<Map<String, Object>> listKeyMaps(String jsonString) {  
  42.         List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();  
  43.         try {  
  44.             Gson gson = new Gson();  
  45.             list = gson.fromJson(jsonString, new TypeToken<List<Map<String, Object>>>() {  
  46.             }.getType());  
  47.         } catch (Exception e) {  
  48.             e.printStackTrace();  
  49.         }  
  50.         return list;  
  51.     }  
  52.   
  53. }  

Map<String,Object> map = new HashMap<String,Object>();
map.put("sex", type);
map.put("marriage", marriage);
map.put("education", education);
map.put("origin", locationStr);
map.put("address", nowAddressStr + "" + detailsAddressStr);
map.put("contact1", contact1);
map.put("contact1Name", nameStr);
map.put("contact1Phone", phoneStr);
map.put("contact2", contact2);
map.put("contact2Name", nameDownStr);
map.put("contact2Phone", phoneDownStr);
map.put("personalProperty", personalProperty);
map.put("vocation", vocationStr);

Gson gson=new Gson();
String s = gson.toJson(map);


Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐