Jim*_*Jim -4 java android json gson
问题是关于 JsonElement。这就是 Json 中一个键的值。因此允许使用字符串。好像没有空格
为什么以下行给出 JSON 语法异常?
new JsonParser().parse("Nexus 6")
Run Code Online (Sandbox Code Playgroud)
异常堆栈跟踪:
com.google.gson.JsonSyntaxException: com.google.gson.stream.MalformedJsonException: Use JsonReader.setLenient(true) to accept malformed JSON at line 1 column 8 path $
at com.google.gson.JsonParser.parse(JsonParser.java:65)
at com.google.gson.JsonParser.parse(JsonParser.java:45)
Run Code Online (Sandbox Code Playgroud)
更新:
我感兴趣的是将字符串转换为 JsonElement
更新:
为什么这有效?
new JsonParser().parse("Blah");
Run Code Online (Sandbox Code Playgroud)
更新 3:
这也有效:
new JsonParser().parse("Nexus_6")
Run Code Online (Sandbox Code Playgroud)