【问题标题】:JsonParseException: Invalid JSON input. Position: 9. Character: '.'JsonParseException:无效的 JSON 输入。位置:9。字符:'.'
【发布时间】:2018-10-14 11:57:50
【问题描述】:

我正在使用带有 Spring Boot 2.0.1.RELEASE 的 MongoDB。一切似乎都运行良好。我能够使用 MongoRepository 正确执行 CRUD 操作。当我在

中使用 mongodb 查询时
@Query(value = "{address.city:?0}")
public List<Hotel> findByCity(String city);

@Query(value = "{address.country:?0}")
public List<Hotel> findByCountry(String country);

当我尝试使用 url localhost:8090/hotels/address/city/Rome 访问数据时,我收到以下错误响应

{
    "timestamp": "2018-05-04T04:51:43.549+0000",
    "status": 500,
    "error": "Internal Server Error",
    "message": "Invalid JSON input. Position: 9. Character: '.'.",
    "path": "/hotels/address/city/rome"
}

和以下登录控制台:

Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.bson.json.JsonParseException: Invalid JSON input. Position: 9. Character: '.'.] with root cause

org.bson.json.JsonParseException: Invalid JSON input. Position: 9. Character: '.'.

我不知道为什么我在执行GET 请求时收到Invalid JSON input. Position: 9. Character: '.'.

我哪里错了?

【问题讨论】:

  • 缺少引号; @Query(value = "{'address.country':?0}")
  • 谢谢!!!这解决了我的问题。

标签: spring mongodb spring-boot spring-mongodb mongorepository


【解决方案1】:

缺少引号; @Query(value = "{'address.country':?0}")

– 尼尔·伦恩

这对我也有用。

【讨论】:

    【解决方案2】:

    如果您缺少引号,或者可能是由于传递给 MongoDB 的未解析字符串,可能会出现这种情况。尝试使用像\"appname\":1 这样的解析字符串。这是一个投影的例子。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多