java - 在带有空格的字符串上使用 GSON JsonParser

标签 java android json gson

我在这里完全空白 - 在 gson 中解析时没有方便的方法来处理空格?我遇到以下异常:

com.google.gson.JsonSyntaxException: com.google.gson.stream.MalformedJsonException: 
Use JsonReader.setLenient(true) to accept malformed JSON at line 1 column 5 path $

这是我的代码:

jsonArray.add(new JsonParser().parse(id));

其中 id 是带有空格的字符串,例如 Hello World

最佳答案

Hello World 不是有效的 JSON,是吗?不应该是类似 { "Hello World"} 或 { "Something": "Hello World"}

关于java - 在带有空格的字符串上使用 GSON JsonParser,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32055648/

相关文章:

java - 在java中以不同的格式编写图像会产生不同的结果

Java 8 : store and retrieve data in form of a data table

android - 数据库流 'count as'

Javascript/JSON 输出不显示

php - 如何将项目添加到json文件格式的数组

java - 将 ListView 放入 Horizo​​ntalScrollView 的最佳方法是什么?

java - 在不启动事务的情况下通过 Hibernate 对 MySQL 数据库运行查询的含义是什么?

javascript - React Native - "undefined is not an object (evaluating ' MyApp.navigation.openDrawer')

android - android tabwidget 的现有补丁允许左侧的标签?

android - Json 数据已发布到服务器但始终获取 "com.android.volley.ParseError: org.json.JSONException: End of input at character 0 of"