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 对象,包括没有源代码的对象。
- public class GsonTools {
- public GsonTools() {
- }
- public static <T> T getPerson(String jsonString, Class<T> cls) {
- T t = null;
- try {
- Gson gson = new Gson();
- t = gson.fromJson(jsonString, cls);
- } catch (Exception e) {
- e.printStackTrace();
- }
- return t;
- }
- public static <T> List<T> getPersons(String jsonString, Class<T> cls) {
- List<T> list = new ArrayList<T>();
- try {
- Gson gson = new Gson();
- list = gson.fromJson(jsonString, new TypeToken<List<T>>() {
- }.getType());
- } catch (Exception e) {
- e.printStackTrace();
- }
- return list;
- }
- public static List<String> getList(String jsonString) {
- List<String> list = new ArrayList<String>();
- try {
- Gson gson = new Gson();
- list = gson.fromJson(jsonString, new TypeToken<List<String>>() {
- }.getType());
- } catch (Exception e) {
- e.printStackTrace();
- }
- return list;
- }
- public static List<Map<String, Object>> listKeyMaps(String jsonString) {
- List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
- try {
- Gson gson = new Gson();
- list = gson.fromJson(jsonString, new TypeToken<List<Map<String, Object>>>() {
- }.getType());
- } catch (Exception e) {
- e.printStackTrace();
- }
- return list;
- }
- }
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 对象,包括没有源代码的对象。
- public class GsonTools {
- public GsonTools() {
- }
- public static <T> T getPerson(String jsonString, Class<T> cls) {
- T t = null;
- try {
- Gson gson = new Gson();
- t = gson.fromJson(jsonString, cls);
- } catch (Exception e) {
- e.printStackTrace();
- }
- return t;
- }
- public static <T> List<T> getPersons(String jsonString, Class<T> cls) {
- List<T> list = new ArrayList<T>();
- try {
- Gson gson = new Gson();
- list = gson.fromJson(jsonString, new TypeToken<List<T>>() {
- }.getType());
- } catch (Exception e) {
- e.printStackTrace();
- }
- return list;
- }
- public static List<String> getList(String jsonString) {
- List<String> list = new ArrayList<String>();
- try {
- Gson gson = new Gson();
- list = gson.fromJson(jsonString, new TypeToken<List<String>>() {
- }.getType());
- } catch (Exception e) {
- e.printStackTrace();
- }
- return list;
- }
- public static List<Map<String, Object>> listKeyMaps(String jsonString) {
- List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
- try {
- Gson gson = new Gson();
- list = gson.fromJson(jsonString, new TypeToken<List<Map<String, Object>>>() {
- }.getType());
- } catch (Exception e) {
- e.printStackTrace();
- }
- return list;
- }
- }
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);