JSON解析器异常(java)但有效的JSON

时间:2015-01-16 05:34:08

标签: java json

我有以下代码:

    FileReader reader = new FileReader(fileName);
    if (fileName == "") {
      System.err.println("Empty Property File, Intentional?");
    }
    JSONParser jsonParser = new JSONParser();
    JSONObject prop = (JSONObject) jsonParser.parse(reader);

引发以下异常

Unexpected token END OF FILE at position 0.
    at org.json.simple.parser.JSONParser.parse(JSONParser.java:257)
    at org.json.simple.parser.JSONParser.parse(JSONParser.java:92)

我已经检查过JSONlint,它说它是有效的json。

json文件本身是从python字典生成的,如下所示

        with open(localprop, 'w') as fp:
            json.dump(properties, fp)

这是实际的JSON:

{
    "clientjar": "client.jar",
    "nettythreadpool": "38",
    "remotesrcdir": "/local/user/work/src/multiKV/src",
    "servers": [
        {
            "ip": "thor57",
            "sid": "1",
            "type": "1",
            "id": "1",
            "port": "40000"
        }
    ],
    "remoteprojectdir": "/local/user/experiments",
    "gc": {
        "ceilingfreq": "1000",
        "interval": "20000",
        "activated": "1",
        "records": "1",
        "pathcompression": "1",
        "asyncmarkancestors": "1"
    },
    "nbrows": "10000",
    "javacommand": "java -Xss515m -Xms48g -Xmx48g -XX:+UseConcMarkSweepGC -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -jar",
    "trxwrites": "0",
    "experimentname": "helloworld",
    "trxlength": "4",
    "servermain": "multiKV.benchmark.server.StartAndInitialiseServer",
    "accesspattern": "uniform",
    "sid": "1",
    "clientmain": "multiKV.benchmark.clients.StartClientsMain",
    "clientmachines": "3",
    "loadermain": "multiKV.benchmark.loader.PopulateServer",
    "serverjar": "server.jar",
    "nettyreceiver": "6",
    "dependencies": [
        "/home/user/work/libs/netty.jar",
        "/home/user/work/libs/guava-18.0.jar",
        "/home/user/work/libs/netty_allen.jar",
        "/home/user/work/libs/protobuf.jar",
        "/home/user/work/libs/json-simple-1.1.1.jar",
        "/home/user/work/libs/mapdb-1.0.6.jar"
    ],
    "localsrcdir": "/home/user/work/src/multiKV/src",
    "localprojectdir": "/home/user/work/experiments",
    "warmuptime": "15",
    "trxreads": "100",
    "workload": [
        "ro"
    ],
    "logging": {
        "measureput": "0",
        "measurecommit": "0",
        "measurecpu": "0",
        "measurerecords": "0",
        "measurememory": "0",
        "measurestates": "0",
        "measurecompression": "0",
        "measuremerge": "0",
        "measuretree": "0",
        "measurebegin": "0",
        "measureget": "0"
    },
    "trxtype": "1",
    "cid": "1",
    "nbservers": "1",
    "clients": [
        {
            "ip": "thor51",
            "sid": "1",
            "type": "1",
            "id": "1",
            "nbclients": [
                "1",
                "2"
            ]
        },
        {
            "ip": "thor52",
            "sid": "1",
            "type": "1",
            "id": "2",
            "nbclients": [
                "1",
                "2"
            ]
        }
    ],
    "loaderjar": "loader.jar",
    "keysize": "50",
    "debug": "1",
    "runtime": "60",
    "replicators": [
        {
            "ip": "thor56",
            "rid": "1",
            "replicatorPort": "400000",
            "type": "1",
            "clientPort": "50000"
        },
        {
            "ip": "thor56",
            "rid": "2",
            "replicatorPort": "400000",
            "type": "1",
            "clientPort": "50000"
        }
    ]
}

这里发生了什么?

0 个答案:

没有答案