JSONException:: syntax error, expect {, actual EOF, pos 0, line 1, column 1

Full text of error report:

Exception in thread "main" com.alibaba.fastjson.JSONException: syntax error, expect {, actual EOF, pos 0, line 1, column 1
    at com.alibaba.fastjson.parser.DefaultJSONParser.parseObject(DefaultJSONParser.java:197)
    at com.alibaba.fastjson.parser.deserializer.MapDeserializer.deserialze(MapDeserializer.java:70)
    at com.alibaba.fastjson.parser.deserializer.MapDeserializer.deserialze(MapDeserializer.java:43)
    at com.alibaba.fastjson.parser.DefaultJSONParser.parseObject(DefaultJSONParser.java:689)
    at com.alibaba.fastjson.JSON.parseObject(JSON.java:378)
    at com.alibaba.fastjson.JSON.parseObject(JSON.java:282)
    at com.alibaba.fastjson.JSON.parseObject(JSON.java:555)

This is a syntax error when converting string to json.

syntax error, expect {, actual EOF, pos 0, line 1, column 1; syntax error, expect {, actual EOF, pos 0, line 1, column 1; syntax error, expect {, actual EOF, position 0, line 1, column 1

At this time, you need to check whether the String type value to be converted in your code meets the JSON format.

String str="{\"Student\":{\"id\":\"1\",\"name\":\"小明\"}}";
HashMap hashMap = JSON.parseObject(str, HashMap.class);
System.out.println(hashMap);

At this point the console can print out normally.


Guess you like

Origin blog.csdn.net/m0_71867302/article/details/129809434