我有一个Scala
模型
case class Model(
name: String,
site: String,
phones: Seq[String],
duration: String,
pricePerMonth: Double,
address: String,
benefits: Seq[String],
rating: Int
)
{
"name": "a",
"site": "b",
"phones": ["c"],
"duration": "d",
"price-per-month": 10.00,
"address": "e",
"benefits": ["f"],
"rating": 1
}
"com.typesafe.play" %% "play-json" % "2.3.4"
val model = fromInputStream { getClass getResourceAsStream "/model.json"
} getLines() toString
val json: JsValue = Json.parse(model)
但我有个错误
Exception in thread "main" com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'non': was expecting 'null', 'true', 'false' or NaN
at [Source: java.io.StringReader@a7e666; line: 1, column: 4]
at com.fasterxml.jackson.core.JsonParser._constructError(JsonParser.java:1524)
at com.fasterxml.jackson.core.base.ParserMinimalBase._reportError(ParserMinimalBase.java:557)
at com.fasterxml.jackson.core.json.ReaderBasedJsonParser._reportInvalidToken(ReaderBasedJsonParser.java:2042)
at com.fasterxml.jackson.core.json.ReaderBasedJsonParser._reportInvalidToken(ReaderBasedJsonParser.java:2018)
at com.fasterxml.jackson.core.json.ReaderBasedJsonParser._matchToken(ReaderBasedJsonParser.java:1870)
at com.fasterxml.jackson.core.json.ReaderBasedJsonParser.nextToken(ReaderBasedJsonParser.java:657)
at com.fasterxml.jackson.databind.ObjectMapper._initForReading(ObjectMapper.java:3031)
at com.fasterxml.jackson.databind.ObjectMapper._readValue(ObjectMapper.java:2951)
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:1587)
at play.api.libs.json.JacksonJson$.parseJsValue(JsValue.scala:486)
at play.api.libs.json.Json$.parse(Json.scala:19)
有什么想法可以修复这个错误吗?
对我有效。来自REPL:
Welcome to Scala version 2.11.7 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_60).
Type in expressions to have them evaluated.
Type :help for more information.
scala> import play.api.libs.json._
import play.api.libs.json._
scala> val json = """
| {
| "name": "a",
| "site": "b",
| "phones": ["c"],
| "duration": "d",
| "price-per-month": 10.00,
| "address": "e",
| "benefits": ["f"],
| "rating": 1
| }
| """
json: String =
"
{
"name": "a",
"site": "b",
"phones": ["c"],
"duration": "d",
"price-per-month": 10.00,
"address": "e",
"benefits": ["f"],
"rating": 1
}
"
scala> Json.parse(json)
res0: play.api.libs.json.JsValue = {"name":"a","site":"b","phones":["c"],"duration":"d","price-per-month":10,"address":"e","benefits":["f"],"rating":1}
所以问题可能出在你的方法上:
val model = fromInputStream { getClass getResourceAsStream "/model.json" } getLines() toString
我创建了非常简单的流程,我已经附上了下面的图片。 流程描述: 用户发送费用报告,最后它得到审查,应该批准,而我是点击批准按钮。但我得到了如下错误: 变量上的当前json 请问json中的错误是什么,我在名为“onaccept1”的变量上犯了什么错误。
我在通过jackson解析器、ajax和jQuery将对象数组传递给controller时遇到了问题。 我的控制器如下所示: 以下是的结果:
和ContactForm 我不知道到底发生了什么,因为如果我尝试向控制器发送一个带有POSTMAN的JSON,这个主体与相同,一切都很顺利,所以Jackson在幕后做了一些奇怪的事情...