fastjson scala下,如果某个字段的对应值里面有双引号,就会报错

ifmq2ha2  于 2021-11-27  发布在  Java
关注(0)|答案(1)|浏览(424)

如题。。

scala> val str = "{"a":80,"b":"xxx","c":"aa"cc"}"
str: String = {"a":80,"b":"xxx","c":"aa"cc"}

scala> str
res6: String = {"a":80,"b":"xxx","c":"aa"cc"}

scala> def getValidJsonObj(str: String): String = {
| try{
| JSON.parseObject(str)
| "xxValid"
| }catch {
| case e: Exception =>
| "notValid"
| }
| }
getValidJsonObj: (str: String)String

scala> val ans = getValidJsonObj(str)
ans: String = notValid

cfh9epnr

cfh9epnr1#

<dependency>
        <groupId>com.alibaba</groupId>
        <artifactId>fastjson</artifactId>
        <version>1.2.57</version>
    </dependency>

相关问题