这明显不不能解析,只能readline一行一行读取

解决方案 »

  1.   

    加了20分,
    这个格式肯定可以解析的,因为这个是配置文件
    即使自己写工具类  能给个demo么- -
      

  2.   

    txt文件你只能一行行把它读出来....  读出来之后, 这个json格式的数据,你当然可以把它转换成Json啊, 直接从string转换成Json对象就OK了, 推荐jackson..
      

  3.   

    import java.io.BufferedReader;
    import java.io.File;
    import java.io.FileReader;
    import java.util.ArrayList;
    import java.util.List;
    import java.util.Map;
    import java.util.TreeMap;import org.junit.Test;
    /**
     * @author hipo
     */
    public class StringTest { public static List<Map<String, String>> parseStringToList() {
    File file = new File("E:/error.txt");
    BufferedReader reader = null;
    List<Map<String, String>> list = new ArrayList<Map<String,String>>();
    try {
    reader = new BufferedReader(new FileReader(file));
    String id = null;
    int count = 0; // 花括号数,{加1,     }减1
    String tempString = null;
    StringBuilder used_by_heroes = new StringBuilder();
    Map<String, String> map = new TreeMap<String, String>();
    while ((tempString = reader.readLine()) != null) {
    tempString = tempString.replace("\"", "").trim();
    if (tempString.matches("\\d+")) {
    id = tempString;
    map.put("id", id);
    } else if (tempString.equals("{")) {
    count++;
    } else if (tempString.equals("}")) {
    count--;
    if (count == 0) {
    map.put("used_by_heroes", used_by_heroes.toString());
    list.add(map);
    map = new TreeMap<String, String>();
    used_by_heroes = new StringBuilder();
    }
    } else if (tempString.matches("\\S+\\s+\\S+")) {
    if (count == 1) {
    String[] s = tempString.split("\\s+");
    map.put(s[0], s[1]);
    } else if (count == 2) {
    if (used_by_heroes.length() != 0) {
    used_by_heroes.append("#**#");
    }
    used_by_heroes.append(tempString);
    }

    }
    } catch (Exception e) {
    e.printStackTrace();
    }
    return list;
    }

    @Test
    public void test() {
    parseStringToList();
    }
    }
    其中used_by_heroes属性我相信你这应该有很多条,我把这些都拼成一个字符串了,中间用"#**#"隔开的,这个属性需要你后期自己去解析。
    这一条数据应该是对应一个实体类,你可以直接把它映射到实体类中,返回List<Object>