简体   繁体   中英

Scala Json(json4s) parse return None

$             "properties": [
                {
                   "name": "Armour",
                   "values": [
                      [
                         "258",
                         1
                      ]
                   ],
                   "displayMode": 0
                },...]

I have this JSON array.

I use json4s and scala for parse this code.

case class Property(
    name: String,
    values: Option[Option[(String, Int)]] = None,
    displayMode: Int
)

I write case class for this block, but I get "None" when get values...

I need get "258" in this example. What am I doing wrong?

Your Json looks like you have a list of lists under your values property. I guess you want to have something like dictionary which should be with curly brackets instead of just brackets. Other thing is why would you parse that into Option[Option[(String, Int)]]? Try defining that as optional Map[String, Int].

这行得通吗?

values: List[(String, Int)] = Nil

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM