Exception in thread "main" org.json.JSONException: Unterminated string at charac
这是我的hadoop源代码,不知道为什么总出现这个错误,我试过用scaner.next().replaceall().把换行替换但还是出现同样的问题,求助
我的源文件格式是这样的
{"iname":"曹阿山","regDate":"2013年01月22日","id":2253}
四川
{"iname":"唐博湖","regDate":"2013年01月14日","id":2281}
package com.wanfin.hadooptest;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
import org.json.JSONException;
import org.json.JSONObject;
public class Test {
public static void main(String[] args) throws JSONException {
String fullFileName = "E:/data/court_data.txt";
File file = new File(fullFileName);
Scanner scanner = null;
// StringBuilder buffer = new StringBuilder();.replace(/[\n]/ig,'')
try {
scanner = new Scanner(file, "utf-8");
while (scanner.hasNextLine()) {
JSONObject jsonObject = new JSONObject(scanner.next());
String name = jsonObject.getString("areaName");
System.out.println(name);
System.out.println(jsonObject.toString());
}
} catch (FileNotFoundException e) {
} finally {
if (scanner != null) {
scanner.close();
}
}
}
}
出现错误如下:
"iname":"唐付长","regDate":"2013年01月14日","id":2281}
Exception in thread "main" org.json.JSONException: Unterminated string at character 261
at org.json.JSONTokener.syntaxError(JSONTokener.java:410)
at org.json.JSONTokener.nextString(JSONTokener.java:244)
at org.json.JSONTokener.nextValue(JSONTokener.java:341)
at org.json.JSONObject.<init>(JSONObject.java:205)
at org.json.JSONObject.<init>(JSONObject.java:402)
at com.wanfin.hadooptest.Test.main(Test.java:25)