[英]Scala string - json
I'm new to Scala. 我是Scala的新手。 I have a string as below
我有一个字符串如下
2017-07-07|{"success":true,"data":{"status":"200","message":"Operation completed."}}
I only need the second part of the string. 我只需要字符串的第二部分。 I'm able to using map and split it into string as below
我可以使用map并将其拆分为字符串,如下所示
{"success":true,"data":{"status":"200","message":"Operation completed."}}
but it's suppose to be JSON, and I'm not able to parse it. 但是它应该是JSON,但我无法解析它。 Hope someone can give me some guide.
希望有人能给我一些指导。
val y = "2017-07-07|{\"success\":true,\"data\":{\"status\":\"200\",\"message\":\"Operation completed.\"}}"
val res = y.split('|')(1)
as for JSON serialization you can use lift_json as it can be used independent, just add the dependency to your SBT file and then use the following code to parse the string 至于JSON序列化,您可以使用lift_json,因为它可以独立使用,只需将依赖项添加到您的SBT文件中,然后使用以下代码来解析字符串
import net.liftweb.json._
parse(res)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.