正则表达式
发布时间:2020-12-13 22:40:10 所属栏目:百科 来源:网络整理
导读:package com.jiangchong.MyGsonHelp; import java.lang.reflect.Constructor; import java.lang.reflect.Field; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.HashMap; import java.util.Map; public class GsonHelpT { p
package com.jiangchong.MyGsonHelp;
import java.lang.reflect.Constructor; import java.lang.reflect.Field; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.HashMap; import java.util.Map; public class GsonHelp<T> { private Field[] field; private Method[] method; private Constructor[] constructors; private ArrayList<String> keyName; private Map<String,String> map; public GsonHelp() { } public T toJson(String json,Class<T> classzz) { // getField(classzz); // getMethod(classzz); // getConstructor(classzz); splitJson(json); return null; } private Constructor[] getConstructor(Class<T> classzz) { constructors = classzz.getConstructors(); for (int i = 0; i < constructors.length; i++) { System.out.println(constructors[i].getName()); } return constructors; } public Method[] getMethod(Class<T> classzz) { method = classzz.getMethods(); for (int i = 0; i < method.length; i++) { System.out.println(method[i].getName()); } return method; } public Field[] getField(Class<T> classzz) { field = classzz.getDeclaredFields(); for (int i = 0; i < field.length; i++) { System.out.println(field[i].getName()); } return field; } public void splitJson(String json) { map = new HashMap<String,String>(); keyName = new ArrayList<String>(); String[] splite = json.split(","); for (int i = 0; i < splite.length; i++) { System.out.println(" " + splite[i]); } System.out.println("===================="); spliteString(splite); } public void spliteString(String[] splite) { for (int i = 0; i < splite.length; i++) { splitStringArray(splite[i]); } } private void splitStringArray(String string) { // String p = "^:"$"; // String[] str = string.split("""); // // System.out.println( str[0] + " " + str[1]); // String kName = ""; // String vName = ""; // int start,end; // boolean isfirst = false; // boolean isstart = false; // int i,j; // for (i = 0; i < str.length; i++) // { // start = 0; // end = 0; // isfirst = false; // isstart = false; // for ( j = 0; j < str[i].length(); j++) // { // if (str[i].charAt(j) != '{' && str[i].charAt(j) != '"' && isstart == false) // { // System.out.println(str[i].charAt(j) + " zzzzz"); // System.out.println(j); // start = j; // isstart = true; //开始了 // } // else if (str[i].charAt(j) == '"' && isfirst == true) // { // end = j; //结束了 // break; // } // else if(str[i].charAt(j) == '"') // { // isfirst = true; // } // } // if(j == str[i].length() && str[i].charAt(j - 1) != '"') // { // end = str[i].length(); // vName = str[i].substring(start,end); // } // else if (i == 0) // { // kName = str[i].substring(start,end); // } // else if (i == 1 && isstart == true && isfirst ==true) //开始了 结束了 // { // vName = str[i].substring(start,end); // } // else if (i == 1 && start == end && isfirst == isstart && isstart == false) // { // vName = ""; // } // // // } // System.out.println(string); String p = "^"";//引号开头 String p2 = """;//引号 String p3="":";// ": String p4 = "|"; String p5="^{";//{开头 String p6 ="}$";//{结尾 // System.out.println(p3 + "p3"); // System.out.println(p3+"|"+p2); String[]str = string.split(p5+"|"+p6+"|"+p3 + "|" + p2); // System.out.println(str.length); for(int i = 0; i < str.length; i++) { System.out.print(str[i]); } System.out.println(""); // map.put(kName,vName); // keyName.add(kName); // System.out.println( kName+ " " + vName); } }
给自己看的 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
推荐文章
站长推荐
热点阅读